Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

gitolite

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?

like image 278
MrNemus Avatar asked Sep 21 '11 21:09

MrNemus


People also ask

What is master in git push origin master?

One can push and pull data from a remote repository when you need to share work with teams. Origin and Master are two different terminologies used when working and managing the git projects. Origin is the name used for the remote repository. Master is the name of the branch.

What does git push origin head mean?

git push origin HEAD:master : This will push your local main branch to the existing remote master branch. git push origin HEAD : This will push your local main branch to the branch of the same name on the remote , in other words, this will create a new branch on the remote called main .

What does git push origin do?

Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin. Behavior could be changed via git config.

What does push origin master mean?

git push origin master will push your changes to the remote server. "master" refers to master branch in your repository. If you want to push your changes to any other branch (say test-branch), you can do it by: git push origin test-branch. This will push your code to origin of test-branch in your repository.


2 Answers

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.

like image 196
Lily Ballard Avatar answered Nov 01 '22 12:11

Lily Ballard


master:refs/heads/master is a refspec.

refspecs are of the form +<src>:<dst>

So here master is the ref on your local repo that you are pushing to the refs/heads/master refspec on the remote (origin). master is short for refs/heads/master actually.

In fact, you can just do git push origin master whereby it will push master on your local to master on remote. Only when you want to push to a different ref do you need to explicitly specify the destination ref.

Also just git push has default behaviour too, which probably wouldn't have been the case before you did the first push and created a branch (master ) on the remote. So it would have seemed like you need to do the command you had mentioned. Refer to the manual

like image 5
manojlds Avatar answered Nov 01 '22 11:11

manojlds