How to tell Git to always pull the master branch?

若如初见. 提交于 2019-12-02 18:38:29
mipadi

What does "your configuration file" mean here?

Your repo's configuration file, found at .git/config at the root of your repo. (There's also a per-user global config file at ~/.gitconfig, but you don't want to put repo-specific settings there.)

Which file should I edit, and what exactly should I type in?

You can use the git config program to write configuration information, instead of entering it manually. However, if you want to do it manually, just open up .git/config -- the syntax is fairly straightforward.

What's nickname in this case?

Nickname, in this case, is the name of the remote -- so "stick". You don't have to worry about the remote.* options, as those have already been set up, but you do need to set the branch.* options. These options tell Git what to merge when doing a git pull from stick.

Say you want to merge in master from stick when doing a git pull from stick. You can do so like this:

# Sets stick as default remote for git pull.
# Note that origin will no longer be the default remote for git pull!
$ git config branch.master.remote stick

# Automatically merge in stick's master branch when doing a git pull
$ git config branch.master.merge refs/heads/master

So now, when you do a git pull without any remote or refspec info, it'll fetch all the branches from stick, and merge in stick's master branch. Note that origin will not be the default remote anymore; to merge in origin's master branch, you'll have to use git pull origin master.

If you don't want to change the default remote to stick, you'll have to continue using git pull stick master.

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