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

问题描述 投票:2回答:1

我结帐了一个新分行

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来修改current的设置以使push自动执行我所期望的甚至-u选项,但我喜欢指定-u所以我知道当我设置跟踪时信息。但是,如果我没有指定它,我希望-u自动使用我当前的分支名称。

我可以设置什么选项让-u像我记得的那样表现?

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

$> 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上使用公共存储库时-u可能就足够了,但是当在私有GitHub repos或repos on AWS CodeCommit时,我得到上面列出的错误。

git git-push git-config upstream-branch
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.