. Advertisement .
..3..
. Advertisement .
..4..
I am new to git and searching the “fatal: not a valid object name: ‘master’” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:
git init
git branch
git --bare init
git branch master
The error I’m getting is below:
fatal: Not a valid object name: 'master'.
Please give me the solution to this issue.
The cause:
This is a desirable behavior. Before Git creates a
master
Branch, you must commit something.In a hidden
.git
folder at the root of your project, the same files will be created by a non-baregit init
.This is also a good behavior. There is not master branch until you commit, so the error happens.
Solution:
This error will be solved if you prepare a commit. You can add one or more files into your directory, then
git commit
will create your first commit andmaster
branches.Once you have made your first commit, Git will create a master branch. If there is no code in the repository, then there is no reason to have a master branch.