2

I have a repository that I freshly cloned from github. The address is git://github.com/JoshClose/CsvHelper.git if you want to try this out. I am using tortoisegit, but will use the command line to fix this if need be (I might need my hand held a little for that).

The log looks like this:

*   0.11
|
| * master origin/HEAD origin/master 0.10
| |
|-
|
*   0.9.1

I'm pretty sure after doing the changes for 0.10, that I didn't switch the branch back to 0.9.1 and work on 0.11, but that it was it looks like.

What I want to do is remove 0.11, switch to 0.10, make the changes for 0.11 that I need, then push to github. The changes are small, but I could merge the two, I suppose.

After the changes, the log looks like this:

* (this has no label/branch name)
|
* master origin/HEAD origin/master 0.10
|
* 0.9

Why didn't master get switched to my new changes?

When I do this and try pushing to github, or make any changes and push, I get the error:

git.exe push    "origin" (no branch)

error: src refspec (no does not match any.
error: src refspec branch) does not match any.
error: failed to push some refs to 'git@github.com:JoshClose/CsvHelper.git'

I've tried the pull them push method of fixing this issue, but that didn't work. Pulling says that everything is up to date. I've tried doing a --force also, but get the same error.

I think there is a problem with master not being set with my new changes. When I go to push to github, the branch I'm on says (no branch).

What can I do to fix this? I'm ready to just delete the repository and start over.

Josh Close
  • 22,935
  • 13
  • 92
  • 140

1 Answers1

4

You must have checked out directly a tag or a SHA1 commit, making in the process a detached HEAD.
All your updates/modifications took place in this unnamed branch reference by said "detached HEAD".

Before pushing, you should create (declare) a branch, or merging master with HEAD (fast forward) merge.

git branch tmp
git checkout master 
git merge tmp # fast-forward master

That should give you:

* (master,tmp)
|
* origin/HEAD (origin/master) 0.10
|
* 0.9
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What I think happened is, in tortoisegit when you checkout a line that has several branches/tags i.e. `master origin/HEAD origin/master 0.10` it checks out the tag. I explicitly checked out master instead, and then my changes didn't happen in a detached head. I was able to fix my local repo with your suggestions, but then couldn't push still, so I did a force and it worked this time. – Josh Close Apr 28 '10 at 14:18
  • @VonC: your description of the problem was exactly what I did late night... I remember that I saw something related to detached in my Mac OS Terminal Window hahaha... I'm starting to play with git and github. It's awesome! As a result of getting a detached HEAD, I got a ( no branch ) option when pushing within Xcode IDE. Everything makes sense now. Executed the 3 lines you provided and the thing started working again - no more no branch option. :) – Leniel Maccaferri Aug 23 '11 at 16:29
  • @Leniel: glad this answer helped you :) The other linked answers detail the "detached HEAD" situation (http://stackoverflow.com/questions/2519031/git-head-has-disappeared-want-to-merge-it-into-master/2519055#2519055, http://stackoverflow.com/questions/999907/git-push-says-everything-up-to-date-even-though-i-have-local-changes/1000009#1000009) – VonC Aug 23 '11 at 17:04