git remote与不同的pull / push url如何避免在推送后获取步骤?

时间:2016-06-23 10:32:19

标签: git

我的配置看起来像这样

[remote "upstream"]
    url = https://github.com/theteam/foo.git
    fetch = +refs/heads/*:refs/remotes/upstream/*
    pushurl = https://github.com/me/foo.git
[remote "myfork"]
    url = https://github.com/me/foo.git
    fetch = +refs/heads/*:refs/remotes/myfork/*
[branch "master"]
    remote = upstream
    merge = refs/heads/master

事实上,我已经推送了theteam/foo.git回购,但我想完全确定不要意外推送。因此,pushurl配置为使用我自己的帐户,其中克隆了foo.git

问题是,当我git pull(本地主分支从上游仓库更新),然后git push(我自己的克隆得到更新)时,我仍然需要git fetch myfork,否则我的本地/remote/myfork未更新。这有时让我感到惊讶,因为git show remote myfork告诉我每一件事都是最新的。

我的配置中缺少什么,以便git push执行git fetch myfork后续步骤?

1 个答案:

答案 0 :(得分:0)

由于上游远程不知道remotes / myfork refspec,因此无法更新此类跟踪引用。 (我想知道它是否更新遥控器/上游/主人)

可能你要找的是分支。名称 .pushRemote:

...
[branch "master"]
 remote = upstream
 pushRemote = myfork
 ...

然后push将知道正确的远程上下文

ps:对我来说看起来很有效(git-2.0.0):

$ git log --oneline --decorate --no-color
2a1baf2 (HEAD, master) r1
4e9c27d (upstream/master, upstream/HEAD, origin/master) u2
deb02c0 u1
$ cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "upstream"]
        url = /home/nemo/so2/upstream
        fetch = +refs/heads/*:refs/remotes/upstream/*
        pushurl = ../origin/
[branch "master"]
        remote = upstream
        pushRemote = origin
        merge = refs/heads/master
[remote "origin"]
        url = ../origin/
        fetch = +refs/heads/*:refs/remotes/origin/*
[push]
        default = simple
$ git push
Counting objects: 1, done.
Writing objects: 100% (1/1), 170 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To ../origin/
   4e9c27d..2a1baf2  master -> master
$ git log --oneline --decorate --no-color
2a1baf2 (HEAD, origin/master, master) r1
4e9c27d (upstream/master, upstream/HEAD) u2
deb02c0 u1
$