How do I squelch “fatal: The upstream branch of your current branch does not match the name of your current branch”?

匿名 (未验证) 提交于 2019-12-03 00:55:01

问题:

There is a related question on SO dealing with how to change the parameters of the push command to avoid this message:

fatal: The upstream branch of your current branch does not match the name of your current branch

I'm interested in how to squelch the message itself, without changing the names of my local/remote branches or using fancy push commands.

Suppose I have a local branch tracking a remote branch of a different name:

user@home:~ git branch -vv branch-name abcd1234 [remote/origin/branch-name] last commit message 

Now I want to be able to push my commited changes by simply typing git push. When I do this, I get the following message:

fatal: The upstream branch of your current branch does not match the name of your current branch.  To push to the upstream branch on the remote, use      git push origin HEAD:remote/origin/branch-name  To push to the branch of the same name on the remote, use      git push origin branch-name 

How do I force git to automatically push to the upstream branch even if the names don't match? I'm using git 1.9.1

回答1:

Newer Git (v 1.9 or newer)

git config --global push.default upstream 

Older Git

git config --global push.default tracking 

Git 2.3 still accepts tracking as a synonym for upstream

Just do that once and whenever you "git push" it will push your current branch to its configured upstream.

This also sets it in your global config, which might be shadowed by a different setting in your repository config.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!