Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Git repository has no "master" branch

Tags:

git

I just created a new git repository and only did one commit. Now I do not see a master branch. These are roughly the commands I ran.

  • git init
  • git checkout -b dev
  • (I made some changes to the monitored directory)
  • git add --all
  • git commit -m "a message"

Now when I do a "git branch -a" I do not see a master and if I do "git checkout -b master" I get an error. After reading "fatal: Not a valid object name: 'master'" I see that this is expected behavior. My understanding is that it is typical (and desirable) for repositories to have a master branch.

So I have 2 questions. What are the steps that I should have followed to keep the master branch? What should I do now to get the master branch back?

Thank you in advance for any help
Joe

like image 544
Joe Avatar asked Feb 14 '23 13:02

Joe


1 Answers

The "master" branch has no special status. You can create it or delete it whenever you want just like you would with any other branch.

You'd have gotten a master if you'd committed before creating a branch yourself (so if you'd done your step 2 after the first commit).

Now if you just:

git checkout -b master

You'll have a master branch.

like image 95
Mat Avatar answered Feb 27 '23 12:02

Mat