3

I know that it would be easier to use git push origin master, but if I do:

git push origin .git/refs/heads/master:.git/refs/remotes/origin/master 

I get:

fatal: remote part of refspec is not a valid name in .git/refs/heads/master:.git/refs/remotes/origin/master

Why doesn't this work?

I'm only trying to follow:

git push [remotename] [localbranch]:[remotebranch]
Terry
  • 639
  • 2
  • 7
  • 7
  • Related: [git push origin gives remote part of refspec is not a valid name](http://stackoverflow.com/q/11945289/456814). –  May 28 '14 at 00:31

1 Answers1

4

Refspecs aren't relative path names, "absolute" refspecs just start with refs/. The most "absolute" version of what you are trying to push would be:

git push origin refs/heads/master:refs/remotes/origin/master

However, this is not equivalent to git push origin master. What this does is updates the remote's remote tracking branch origin/master so that it may or may not reflect what its remote origin is actually at.

The equivalent of git push origin master would be:

git push origin refs/heads/master:refs/heads/master
CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • refs/heads/master is different from branch master on my local machine? – Terry Sep 06 '11 at 09:02
  • refs/heads/master is different from my local branch master? refs/remotes/origin/master is different from my remote branch master on github? Why do you use refs/heads/master instead of refs/remotes/origin/master? – Terry Sep 06 '11 at 09:04
  • I'm not sure I understand the first three of your questions. `refs/heads/master` is the name of the local master branch on any repository. When you do `git push origin master` you are updating the remote's master branch to match your local master branch. The left hand side of the colon in a push refers to the ref to push on your local repository, the right hand side of the colon refers to the ref to push to on the remote repository. You (almost) never want to push _to_ a remote tracking branch of a remote repository. They are just the remote's copy of its remote's branches. – CB Bailey Sep 06 '11 at 09:18
  • What I have in refs/remotes/origin/master, is in fact in my local machine? I mean, refs/remotes/origin/master is used with git diff? So, it's a copy of the remote branch, but this is not the real remote branch. – Terry Sep 06 '11 at 09:21
  • @Terry: Any repository which has been made via `git clone` will have a set of remote tracking branches under `refs/remotes/origin` so a ref called `refs/remotes/origin/master` is likely to exist on both your local and remote repositories. When you do a fetch, by default, all branches on the remote (`refs/heads/*`) are copied to the local repository under (`refs/remotes/origin/*`) as remote tracking branches so that you can perform git operations (e.g. rebase, merge, log, etc.) on the remote branches. – CB Bailey Sep 06 '11 at 09:27