0

Can somebody tell me how to get back to my main Git root directory? My command prompt was pointing to

c:/Sites 

but now, the command prompt is pointing to:

c/Sites (new_branch)

Not sure how I got there but I suspect that I must have accidentally created a new branch. I tried "git branch" but returned no results. Also tried "git checkout master" but got an error: "pathspec master did not match any file(s) known to git."

I'm on windows 7. Thanks!

Vee
  • 1,821
  • 3
  • 36
  • 60
  • Are you confusing directories (in your filesystem) with Git branches? Are you on Windows? Do you mean `C:\Sites` rather than `C:/Sites`? What exactly do you mean by "I'm stuck in `c/Sites (new_branch)`; what command produced that output? – Keith Thompson Mar 10 '14 at 01:02
  • What does `git branch -a` output? – Ruslan Osipov Mar 10 '14 at 01:10
  • Indeed, this question needs a lot of editing for clarity. – aruisdante Mar 10 '14 at 01:10
  • Keith: I'm using windows so yes, the path is c:/Sites. The prompt is defaulting to "c/Sites (new_branch)" whereas before the prompt was simply my root path, "c/Sites" – Vee Mar 10 '14 at 01:12
  • Ruslan: git branch -a doesn't list anything. I typed it in and simply get a new command prompt. No branches are listed. – Vee Mar 10 '14 at 01:12
  • did you already commit something in this repo? If not, delete the `.git` folder and re-create the repo with `git init`. It's a bit confusing that `git branch` shows absolutely nothing, so I assume you did something completely wrong and it would be the best to re-init the repo. If you're unsure whether you did anything in the repo, ask `git log` to give you the list of commits you already did. Or open `gitk` in your repo. If there are no commits, simply re-init (http://stackoverflow.com/q/1213430/520162) – eckes Mar 10 '14 at 08:34
  • aruisdante - your comments need to add more value, indeed. – Vee Mar 10 '14 at 15:29

3 Answers3

1

This means that your directory is now tracked by Git. Since you have that error try to do:

git checkout new_branch

Alternatevely

git checkout -b master
koninos
  • 4,969
  • 5
  • 28
  • 47
  • Thanks, Koninos. Worked perfectly! Miyurz provided the same solution but he and I went back and forth a few times so I accepted his answer. Still, thanks for the multiple solutions! – Vee Mar 10 '14 at 15:25
1

Since, you do not see anything with ls -l .git/refs/heads , it implies that you no longer have master branch (may be you deleted your master branch unknowingly as you said above you weren't sure when you accidentally created your branch.

To go back to your original master branch, check your git log for when you created the new branch. once you obtain the commit sha , recreate you master branch with "git checkout -b master ". This will take you to your default prompt.

Mayur Nagekar
  • 813
  • 5
  • 13
  • Thanks, Miyurz. That did the trick! Have no idea what happened but I'm good now! – Vee Mar 10 '14 at 15:25
0

You should be able to do

git checkout master

to go back to master..

XeroxDucati
  • 5,130
  • 2
  • 37
  • 66