Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I've lost both my master branch and according to GIT, my HEAD (though I could have told it that). How do I get them back?

Tags:

git

I'm not entirely sure of the steps that caused this however I have ended up without my GIT master branch.

I had a crack at fixing things using the instructions here: http://sitaramc.github.com/concepts/detached-head.html however my general ignorance of GIT may have left me in a worse pickle than I started out.

$ git branch
  first-cucumber-attempt
  notifications
* second-cucumber-attempt
  sendgrid-setup

At some point I apparently started working on a detached HEAD and now I don't know how to find my master (I feel a little like Alice right now).

Attempting to checkout master gives:

$ git checkout master
  error: pathspec 'master' did not match any file(s) known to git.

Attempting to pull master gives:

$ git pull origin master
From github.com:petenixey/kind-advice
 * branch            master     -> FETCH_HEAD
Already up-to-date.

The branch, "second_cucumber_attempt" has all of the code I want to merge into master and master is still safe on github but I can't get to it. I am thoroughly stuck.

like image 380
Peter Nixey Avatar asked Jan 12 '11 19:01

Peter Nixey


People also ask

How do I go back to head in git?

To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).

How do I find my git head?

One can check your HEAD using git show HEAD command. We have 2 commits and our HEAD is now pointing to the most recent commit we have done. You can also check this in your . git/refs/heads folder.


1 Answers

The "master" in git checkout master is supposed to be a branch, which you do not have. You can checkout the remote's master and make it your own with git checkout origin/master -b master, which should also set it up as a "tracking branch".

You can see your list of remote branches with git branch -r.

like image 133
wnoise Avatar answered Oct 16 '22 01:10

wnoise