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

后端 未结 1 669
孤独总比滥情好
孤独总比滥情好 2020-12-20 03:24

Question

What\'s the difference between:

$ git remote add origin git@github.com:yourname/yourproject.git
$ git config remote.origin.push refs/heads         


        
相关标签:
1条回答
  • 2020-12-20 03:55

    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.

    0 讨论(0)
提交回复
热议问题