拉和推的默认遥控器不同,同时允许手动指定一个

时间:2018-06-16 09:19:10

标签: git git-push git-pull git-remote

我有一个本地Git存储库,它有两个遥控器。 originupstream的分支。我在master工作。我想实现这个目标:

  • git pull相当于git pull upstream master
  • git push相当于git push origin master
  • git pull origin master来自origin
  • git push upstream master推送到upstream

因此,将originupstream同步的工作流程将简化为

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 :(得分: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命令的语义,部分是因为我不知道如何,但也部分是因为它可能会在某些时候引起混乱。