Jan Michael Tan
Jan Michael Tan

Reputation: 299

git push question

I've been looking around the internet and can't find what this does:

git push origin master:refs/heads/master

What is the difference with just plain:

git push origin master

Thanks.

Upvotes: 4

Views: 158

Answers (2)

Andy
Andy

Reputation: 46514

There is no difference. One is just a more verbose version of the other.

master:refs/head/masteris saying push your local master to the remotes refs/head/master

For more details, look at the last portion of this page.

Upvotes: 3

Mark Longair
Mark Longair

Reputation: 468081

In versions of git before v1.5.5.2 there was an important difference between these commands. You needed to use the full name of the ref on the destination side of the refspec if that branch did not already exist. (The commit that changed this behaviour has an interesting description of the change.)

In current versions of git there is no difference between the two, as long as master is unambiguous in the destination repository - this is almost always the case, unless you've done something deliberately confusing like create a tag called master. When you do git push origin master, git tries to interpret master as a refspec. Since this refspec has no : separating the source and destination refs, it assumes by default that you mean:

git push origin master:master

... and those incomplete ref names are expanded to refs/heads/master on both sides (again, as long as master is unambiguous both in the source and destination repositories).

Upvotes: 6

Related Questions