Why did I lose my master branch after running `git checkout -b 3_1`?


I'm using Git Bash 2.9.0-64-bit in win7 64bit.

I created a git repository called lec_yaac. This is the related information about branch master:

[email protected] MINGW64 /d/Git/lec_yaac (master)

After I executed command git checkout -b 3_1,it changed to

[email protected] MINGW64 /d/Git/lec_yaac (3_1)

And I added and commmited some files.

But when I executed git branch,it only shows,

  • 3_1

There is nothing about branch master.

And git checkout master returns

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

There is nothing special about a master branch. It is just like any other branch. And a branch is necessarily nothing but a pointer to a commit. So, the branch comes into the picture as soon as you make a commit.

You'd have gotten a master branch if you'd committed before creating a branch yourself.

What you did -
1. Created a repo
2. Created and switched to a new branch (3_1)
3. Committed to 3_1

What you should have done -
1. Created a repo
2. Committed something to master (the default branch name)
3. Created and switched to a new branch (3_1)
4. Committed to 3_1

If you still want a master branch, just create one.

git checkout -b master

Although this will now be pointing to the latest commit in your previous branch 3_1