我有一个本地Git存储库,它有两个遥控器。 origin
是upstream
的分支。我在master
工作。我想实现这个目标:
git pull
相当于git pull upstream master
git push
相当于git push origin master
git pull origin master
来自origin
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.
有什么想法吗?
答案 0 :(得分:2)
这实际上应该在Git版本> = 2.0中开箱即用,就像配置事物一样。
显然,根据评论,您还必须明确将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
,您需要达到的目标。
答案 1 :(得分:1)
一个选项,虽然不完全符合您的要求,但可以在.bashrc
文件中为各种命令定义别名:
alias gpull='git pull upstream master'
alias gpush='git push origin master'
然后,就像使用任何普通的UNIX别名一样使用这些别名。我反对尝试改变基本Git命令的语义,部分是因为我不知道如何,但也部分是因为它可能会在某些时候引起混乱。