【问题标题】:Pushing one git branch requires a pull on another?推一个 git 分支需要拉另一个?
【发布时间】:2011-09-19 01:39:08
【问题描述】:

我有点 git n00b,但我在使用分支时遇到了一些困难。我不认为有人问过这个问题,但可能只是我没有在寻找正确的关键字。

情况: 我有一个远程 git 存储库,并且我已经检查了机器 1 上的 master 分支。 我在机器 2 上做了同样的事情,只是我创建了一个新分支(沙箱)并检查了它。

我在机器 2 上拉取、更改、提交和推送内容 - 没问题。

然后我在机器一上进行一些更改,提交并尝试推送,但我收到此错误:

To xxx@xxx.xxx.com:/project.git
! [rejected]        sandbox -> sandbox (non-fast-forward)
error: failed to push some refs to 'xxx@xxx.xxx.com:/project.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

如果我执行 git pull,我会得到:

Already up-to-date.

所以现在我不得不

git checkout sandbox
git pull
git checkout master
git push

然后一切都很好。在我看来,鉴于这些是不同的分支,我应该没有必要在沙箱分支上拉动以将更改推送到 master。如果我试图将它们合并回来,我可以理解,但这可能永远不会发生。

我怀疑我的配置文件有点错误,所以在这里:

(Machine 1 - master) .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[gui]
    wmstate = normal
    geometry = 1920x970+0+0 368 203

[remote "origin"]
    url = xxx@xxx.xxx.com:/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
    remote = origin
    merge = refs/heads/master

还有

(Machine 2 - paid) .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git+ssh://xxx@xxx.xxx.com/project.git

[branch "master"]
    remote = origin
    merge = refs/heads/master

[branch "sandbox"]
    remote = origin
    merge = refs/heads/sandbox

需要注意的是,同样的问题发生在逆向中 - 在推送 master 之后,如果不检查 master、执行拉取然后切换回沙盒,我就无法推送沙盒。

必须有更简单的方法 - 任何帮助将不胜感激。

【问题讨论】:

    标签: git branch git-branch


    【解决方案1】:

    找到答案:

    git config --global push.default tracking
    

    这似乎已经通过问题解决了。

    This Site提供的答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 2020-07-12
      • 2017-12-18
      • 2020-06-09
      相关资源
      最近更新 更多