如果我创建一个新分支并尝试推送它,则会被告知必须明确说出上游分支的名称。
> git checkout -b feature/long-branch-name-I-dont-want-to-have-to-type-out
Switched to a new branch 'feature/long-branch-name-I-dont-want-to-have-to-type-out'
> git push
fatal: The current branch feature/long-branch-name-I-dont-want-to-have-to-type-out has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/long-branch-name-I-dont-want-to-have-to-type-out
有什么方法可以不必输入上游分支的名称吗?实际上,我一直希望它在服务器上与本地名称相同。
有什么方法可以执行类似的操作git push --set-upstream <current_branch_name>
,而与当前分支名称的名称无关吗?
[编辑] sajib khan的第一个答案,设置push.default
为current
会启用推送,但实际上并没有设置上游。这意味着,未来的后git fetch
,你的Git不会报告提前/计数的背后,你的Git会不知道上游使用的git rebase
或git merge
(或git pull
任何虽然我建议回避git pull
)。
您可以使用[编辑,如他回答的第二部分]:
git push -u origin HEAD
如果需要,这将在另一个Git上创建分支,以便您的Git获取该origin/
变体。然后,无论如何,它会将您拥有的(也许是新的)远程跟踪分支设置为分支的上游。但是直到origin/feature/long-branch-name-I-dont-want-to-have-to-type-out
实际存在,您才能将其设置为上游。1个
1实际上,您可以,但您只是无法使用git branch --set-upstream
它。而且,您还是不想再次键入它。要“手动”执行此操作,您需要:
git config \
branch.feature/long-branch-name-I-dont-want-to-have-to-type-out.remote origin
git config \
branch.feature/long-branch-name-I-dont-want-to-have-to-type-out.merge \
feature/long-branch-name-I-dont-want-to-have-to-type-out
这意味着要键入三遍(!),或者自己编写脚本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句