git push origin master:refs/heads/master what does this do

MrNemus picture MrNemus · Sep 21, 2011 · Viewed 17.4k times · Source

When I create a new repo on my gitolite repository I always have to enter the following command before I can start pushing code to the server.

git push origin master:refs/heads/master

What does it do ?

My guess is that is has to do with the head reference not sure. Could someone explain it to me?

Answer

Lily Ballard picture Lily Ballard · Sep 21, 2011

There's three parts to this command:

git push

This invokes the push command

origin

This names the remote to which you are pushing. This is either one of the named remotes stored in .git/config (you can list these with git remote), a URL, or the token . which means the current repository.

master:refs/heads/master

This is called a "refspec", and you can read about it in the man page for git push. But in general, it's comprised of two parts, separated by a colon. The first part is the name of a local branch, and the second part is the name of a branch on the remote repository (in this case, origin). This particular refspec could be shortened to master:master.

In general, one can shorten refspecs even further. Just specifying master as the refspec is equivalent to using the same name on the remote, so master is the same as master:master.