12

Some repository clones I have allow me to do this:

% git pull
% git push

But other repositories require me to type:

% git pull origin master
% git push origin master

I think I am missing something in the latter case - does anyone know what is (not) going on here? I am using the latest git version, just obviously not using it well.

Paul Beckingham
  • 14,495
  • 5
  • 33
  • 67
  • Duplicate of [How do you make an existing Git branch track a remote branch?](http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch) –  May 23 '14 at 18:37

3 Answers3

13

If you cd into your repository directory and then open up your .git/config file in an editor.

Append this to the end of the file:

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

This is pretty much just an alias so git knows by default to pull from origin master.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Brian Gianforcaro
  • 26,564
  • 11
  • 58
  • 77
13

Or if you prefer, you can do the same thing Brian Gianforcaro proposed from the command line:

git config branch.master.remote origin
git config branch.master.merge  refs/heads/master
Aristotle Pagaltzis
  • 112,955
  • 23
  • 98
  • 97
6

Also, to avoid having to do git push master, you can specify what branches to push in your Git config file, like so:

[remote "origin"]
        ...
        push = master
mipadi
  • 398,885
  • 90
  • 523
  • 479