Git: make existing branch track remote branch

If you have an existing branch, say master, that was not cloned from a remote repository, a git pull without further arguments will give you the following error message:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull ').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "master"]
remote =
merge =

[remote ""]
url =
fetch =

See git-config(1) for details.

Editing .git/config by hand is cumbersome, and I never can remember what the “syntax” for is.

As of git 1.7.0, it is now really easy to set this up:

git branch --set-upstream master origin/master

which will put the following into your .git/config

[branch "master"]
remote = origin
merge = refs/heads/master

Now you can git pull and the remote changes in origin/master will be automatically merged into your local master branch.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: