How do you get git to always pull from a specific branch?
git branch --set-upstream master origin/master
This will add the following info to your config
file:
[branch "master"]
remote = origin
merge = refs/heads/master
If you have branch.autosetuprebase = always
then it will also add:
rebase = true
If you prefer, you can set these options via the commmand line (instead of editing the config file) like so:
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
Or, if you're like me, and want this to be the default across all of your projects, including those you might work on in the future, then add it as a global config setting:
$ git config --global branch.master.remote origin
$ git config --global branch.master.merge refs/heads/master
Under [branch "master"]
, try adding the following to the repo's Git config file (.git/config
):
[branch "master"]
remote = origin
merge = refs/heads/master
This tells Git 2 things:
- When you're on the master branch, the default remote is origin.
- When using
git pull
on the master branch, with no remote and branch specified, use the default remote (origin) and merge in the changes from the remote master branch.
I'm not sure why this setup would've been removed from your configuration, though. You may have to follow the suggestions that other people have posted, too, but this may work (or help at least).
If you don't want to edit the config file by hand, you can use the command-line tool instead:
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
I find it hard to remember the exact git config
or git branch
arguments as in mipadi's and Casey's answers, so I use these 2 commands to add the upstream reference:
git pull origin master
git push -u origin master
This will add the same info to your .git/config, but I find it easier to remember.