please try to create any file in master branch and commit. Then create other branch . It should work.
The git error "fatal: Not a valid object name master" shows that the local repository has no branch named "master". That branch is important as it is the main branch name for git and some git commands depend on it, e.g. the one that fails in your case. This is despite you fetched all the remote references (incl.
The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.
Whenever we need to push the changes to a remote repository, we use git push along with the remote repository “origin” and “master” branches. The term used is “git push origin master“. To pull the changes from the remote repository to local, we use git pull along with remote repository “origin” and “master” branch.
When I
git inita folder it doesn't create a master branch
This is true, and expected behaviour. Git will not create a master branch until you commit something.
When I do
git --bare initit creates the files.
A non-bare git init will also create the same files, in a hidden .git directory in the root of your project.
When I type
git branch masterit says "fatal: Not a valid object name: 'master'"
That is again correct behaviour. Until you commit, there is no master branch.
You haven't asked a question, but I'll answer the question I assumed you mean to ask. Add one or more files to your directory, and git add them to prepare a commit. Then git commit to create your initial commit and master branch.
Git creates a master branch once you've done your first commit. There's nothing to have a branch for if there's no code in the repository.
First off, when you create a "bare repository", you're not going to be doing any work with it (it doesn't contain a working copy, so the git branch command is not useful).
Now, the reason you wouldn't have a master branch even after doing a git init is that there are no commits: when you create your first commit, you will then have a master branch.
You need to commit at least one time on master before creating a new branch.
copying Superfly Jon's comment into an answer:
To create a new branch without committing on master, you can use:
git checkout -b <branchname>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With