tags:

views:

744

answers:

1

I've ran against a problem whith git push today. I tried to push a branch to the remote repository, but it gave an error.

After some search, i've asked it on the git irc channel, and someone said that the syntax of the push was

git push <remote> <localref>:<remoteref>

Up until now, i just used git push which worked fine. But in this case, it failed.

I tried to push some branch other than the master to the remote server, and i got the following error:

error: src refspec xi-temp-dennis does not match any.
error: failed to push some refs to 'remote.server'

By specifying the localref, it suddenly worken.

My question is, why did I need to specify the localref this time?

+2  A: 

If you do just plain "git push remote" without specifying any refs to push then Git will push all "matching branches". A "matching branch" is one where the name of the branch in the local repo is the same as a branch in the remote repo. The remote repo's branch will be updated using the matching branch from the local repo.

So, if you only have a "master" branch, and the remote repo also has a "master" branch, then just plain "git push remote" will push local master to remote master.

You've created a new branch, "xi-temp-dennis" which must not exist in the remote repo. Therefore Git cannot successfully carry out the default behavior of pushing matching branches (hence the "does not match any" error).

You need to tell Git what the name of the ref should be on the remote side, and it will create it:

git push remote xi-temp-dennis:foo

This would create a remote branch named "foo" that would be updated. However, it's name doesn't match your local branch's name, so you would always need to type this same command (with the xi-temp-dennis:foo) in order to push updates. If you want to be able to just type "git push remote" and have updates work, then you should name the remote branch the same as the local one:

git push remote xi-temp-dennis:xi-temp-dennis
Dan Moulding
yeah, i just came to realize that. When i did git push remote xi-temp-dennis, it would look for a branch called xi-temp-dennis on my local repository, while i thought it would specify the branch on the remote repository.
Ikke