What's the difference between `git config` and `git push --set-upstream`

北城余情 提交于 2019-11-29 12:13:13

No, these are very different. The first config setting, remote.<name>.push sets a default refspec for pushing if no other refspec is specified. By default, doing git push origin will push every branch to a branch with a matching name so long as a branch with that name already existed on the remote. After doing:

git config remote.origin.push refs/heads/master:refs/heads/master

... you will find that git push origin will just push master to master.

The other command you quote, git push -u origin master, sets two different config options if the push is successful:

  • branch.master.remote is set to origin
  • branch.master.merge is set to refs/heads/master

These essentially say that master in origin should be regarded as the default "upstream" branch of your master branch. Their most obvious effect is to provide a default action for git pull when you are on master, but are also used in a variety of other situations, such as providing the helpful message at the top of git status that tells you where master is compared to origin/master. These settings are not, however, used to inform the default action of git push and git push origin unless you have also set the config option push.default to tracking (or upstream in recent versions).

So, as a very approximate summary, setting remote.<name>.push affects the default action of git push, while git push -u origin master sets config options that usually just affect the action of git pull.

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