Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github how to fix error: refname refs/heads/new_branch not found

Tags:

git

github

I'm really new to GitHub.

I made my first project and want to add it to GitHub. But when I try to add my project to GitHub I'm getting the following error and I couldn't find a way to fix it.

git branch -M main

error: refname refs/heads/new_branch not found

fatal: Branch rename failed

Any help will be appreciated.

like image 332
Alpay Palabıyık Avatar asked Nov 23 '20 18:11

Alpay Palabıyık


Video Answer


2 Answers

git branch -M is for renaming a branch.

If makes sense if you have a current master branch that you want to rename as main.

Make sure that your new local project has:

  • at least one commit
  • done on a master branch
  • pushed with git push -u origin master
like image 91
VonC Avatar answered Sep 28 '22 02:09

VonC


I solved this thanks to this guide,

Apparently and I do not know why the steps given by the Github guide are not in the correct order and if I am wrong that someone please explain to me.

I solved it with these steps:

    git init
    git remote add origin [email protected]:<YOUR_REPOSITORY_ADDRESS>
    git add .
    git commit -m "first commit" 
    git branch -M main
    git push -u origin main

steps that the guithub guide gives that for me was a mistake.

echo "# socialdata" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/<YOUR_REPOSITORY_ADDRESS>
git push -u origin main
like image 31
JORGE IVAN GUEVARA PEREZ Avatar answered Sep 28 '22 00:09

JORGE IVAN GUEVARA PEREZ