Since Github started using the name of it’s main branch as main
, when you create a new repository with git init
, it is misaligned with this new standard. Your repository is created with the main branch name Master
.
The following example shows the commands suggested by Github to push files in the new repository, from a repository already existing in yours machine:
git remote add origin [email protected]:nunomazer/my-new-repo.git
git branch -M main
git push -u origin main
However, it is common an error message similar to the following to be shown after the git branch -M main
command:
error: refname refs/heads/master not found
fatal: Branch rename failed
Solving the error “refname refs/heads/master not found”
In general this problem is presented because a branch is a pointer that points to a particular commit. Yes, simple as that, you have not yet made any commit in this new repository, so your main branch (called master
) does not point to any place, so it virtually does not exist and cannot be renamed.
To solve, follow the usual steps of first commit:
git add .
git commit -m "Initial commit"
And then run the command to rename the branch:
git branch -M main
Grate, it’s solved, you can now push your source files to Github using the expected way for the main branch.
Comments