I have the remote origin set as the default branch for my current branch. I also have an upstream remote which is not the default for the branch. Is there a way to configure a default branch on the remote so when I pull it defaults to that branch?
Here is my .git/config:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:studgeek/knockout.git
[branch "gh-pages"]
remote = origin
merge = refs/heads/gh-pages
[remote "upstream"]
url = git://github.com/SteveSanderson/knockout.git
fetch = +refs/heads/*:refs/remotes/upstream/*
merge = refs/heads/gh-pages
With this I can happily do the following and it defaults to origin/gh-pages
git pull
What I would like to do is just give it the remote upstream and have it figure out the branch (gh-pages) part so
git pull upstream
rather than this
git pull upstream gh-pages
Right now I get the following if I omit the branch:
$ git pull upstream
You asked to pull from the remote 'upstream', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
I can see three different ways of defaulting that would work for me in my current situations, but I’m not sure how to do any of them :):
* Just use the current branch as the default on the remote upstream
* Indicate a default branch for the upstream remote for the current branch (while leaving origin the default branch)
* Indicate a default branch on the remote. The danger here of course if I switch branches the default upstream branch stays the same. In my case that would be fine, but I can see that burning folks who didn’t expect it.
Note specifying git branch for remote asks a similar question, but the solution requires doing one of two things we don’t want to do – changing the default remote or explicitly listing the branch (we want this codified to avoid manual error).
In the .git/config, you can supply the information. Example if you are in branch
fooand you want to pull remotely frommooNext time you run
git pullin branchfoo, it will pull frommoo.This has been covered in stackoverflow => How do you get git to always pull from a specific branch?