1

I could not come back to the master branch. I used several Git Bash command. I am mentioning all those with the result below.

git checkout master

Output:

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

git branch master

Output:

fatal: Not a valid object name : 'greet'.

git branch

git branch -d greet

Output:

fatal:Couldn't look up commit object for HEAD

I searched a lot in Google Search and Stack Overflow, but I could not find any solution. I installed and reinstalled Git several times. Also, I have tried to delete all the folders related to Git to get a solution.

5
  • Which git command did you execute after installing git and before doing git checkout? Did you execute git init or git clone? Commented May 14, 2013 at 6:54
  • 4
    Just so you know, your first attempt is correct (git checkout master) - but there's something wrong with your repository. Commented May 14, 2013 at 6:58
  • Are you saying the git branch produced NO output at all? That indicates something is very wrong with the repository. Can you also add output of git status, please? Commented May 14, 2013 at 7:04
  • There must be a canonical question for this. Where is it? Commented Dec 10, 2023 at 16:26
  • Related: Git for beginners: The definitive practical guide Commented Dec 10, 2023 at 16:26

1 Answer 1

2

git checkout master will do that if you haven't committed any files to it.

mkdir project ; cd $_ ; git init . 

Output:

Initialized empty Git repository in /Users/doon/Desktop/project/.git/

And:

git checkout master 

Output:

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

If you've changed to another branch, git checkout -b branchname, you can switch back to master the same way, git checkout -b master. Once you stage and commit files, you will no longer get that error (assuming you stage/commit to the master branch).

Sign up to request clarification or add additional context in comments.

2 Comments

Now I am in a new problem. I would like to push my local repository to github, I used following command and got result like below. $ git push origin master ssh: connect to host github.com port 22: Bad file number fatal: Could not read from remote repository. Please make sure you have the correct access rights And the repository exists. Can you say what is the solution ?? Where is the problem ??
@FoysalFoysal Probably best to ask that as a new question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.