我有一个本地 Git 存储库,它有两个 Remote 。 origin
是 upstream
的分支。我在 master
上工作。我想实现这一目标:
git pull
等同于git pull upstream master
git push
等同于git push origin master
git pull origin master
从origin
pull
git push upstream master
推送到upstream
因此将 origin
与 upstream
同步的工作流程将简化为
git pull # from upstream
git push # to origin
我已经成功地使用一系列 git config
命令的以下结果配置了第一部分:
[branch "master"]
remote = upstream
merge = refs/heads/master
pushRemote = origin
但是,git push
给我这个错误:
fatal: You are pushing to remote 'origin', which is not the upstream of
your current branch 'master', without telling me what to push
to update which remote branch.
有什么想法吗?
最佳答案
这实际上应该在 >= 2.0 的 Git 版本中“开箱即用”,按照您配置的方式。
显然,根据评论,您还必须显式配置 push.default
至 simple
,即使这是未配置的默认值 push.default
. (将 push.default
设置为 current
也可以,但会删除 simple
为某些推送添加的安全检查。)
请注意,您可以使用 git branch --set-upstream-to
设置任何分支的上游:
git branch --set-upstream-to=upstream/master master
但它确实需要 git config
命令(或直接编辑配置文件——我喜欢自己经常使用 git config --edit
,尤其是修复拼写错误)来设置 pushRemote
以及,您需要实现您想要实现的目标。
关于git - pull 和推的不同默认远程,同时允许手动指定一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50886573/