如何配置“ git push -u”来推断远程分支名称?

时间:2018-08-01 17:56:44

标签: git git-push git-config upstream-branch

我结帐了新分支

git checkout -b mynewbranch

进行一些更改并提交

git add *
git commit -m "Initial commit on this branch"

然后我去推动。由于我尚未设置上游分支,因此git通知我必须指定--set-upstream <remote> <branch>选项。我觉得在过去的几年里我已经能够做到

git push -u

,如果我的当前分支在起源上不存在,它将创建一个具有相同名称的分支,并将其推送至该分支,而无需大惊小怪。但是我最近重新安装了git,现在当我运行git push -u时,它继续抱怨没有上游分支。

我发现我可以修改push.default的设置,以通过将push设置为current使推入自动执行我期望的-u选项,但是我喜欢指定{ {1}},因此我知道何时设置该跟踪信息。但是,如果我没有指定,我希望-u自动使用我的当前分支名称。

我可以设置什么选项以使-u像我回忆起那样起作用?

编辑:我收到的实际错误消息是

-u

更新:经过进一步测试,看来只有私人存储库可能会发生这种情况。我注意到在GitHub $> git push -u fatal: The current branch mynewbranch has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin mynewbranch 上使用公共存储库就足够了,但是在私有GitHub存储库或AWS CodeCommit上使用存储库时,出现上面列出的错误。

1 个答案:

答案 0 :(得分:2)

  

我确实看到--set-upstream-标志已被删除(看起来像在2.15中),并且--set-upstream-to是替代项。

实际上是在Git 1.8中:see heregit 1.8.0 announce

  

git branch --set-upstream”已过时,可以在   相对遥远的未来。
  引入了“ git branch [-u|--set-upstream-to]”,并带有更清晰的参数顺序。

git push uses that same -u shortcut

我总是看到git push -u与参数一起使用:

git push -u origin myBranch

完成后,下一次推送将简单地使用:git push