Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push question

Tags:

git

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.

like image 224
Jan Michael Tan Avatar asked Jan 19 '23 17:01

Jan Michael Tan


1 Answers

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).

like image 63
Mark Longair Avatar answered Jan 25 '23 22:01

Mark Longair