I'm new to git and github and I'm trying to push to my repository. I'm currently following github instructions:
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin [email protected]:vlocateli/Programming_principles_and_pratice.git
git push -u origin main
but when I type
git push -u origin main
I get the following error:
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/vlocateli/Programming_principles_and_pratice.git'
So, I tried the following:
git push origin master
And then I got the following error:
remote: Permission to vlocateli/Programming_principles_and_pratice.git denied to vlocateli.
fatal: unable to access 'https://github.com/vlocateli/Programming_principles_and_pratice.git/': The requested URL returned error: 403
How do I fix this error?
CodePudding user response:
I also faced the same error 2 weeks ago. I uninstalled git from my system and re-installed it. I logged back into my github account and it worked for me. Try doing that.
If that does not work then try the following steps;
- Do you have a name of the repo? If yes, instead of using the origin, try passing the repo name
git remote add repo_name url
- Again, for the final step
git push repo_name
CodePudding user response:
This is being caused because your remote Git repository does not know about your local repository.
So, you need to set the remote branch as upstream branch of your local branch.
One liner : git push --set-upstream origin master
So, you want your local main to push to remote github
main
repo.
Detailed
mkdir custom-project
cd custom-project
touch README.md
git init
git remote add origin ssh-version-.git
git add README.md
git commit -m "initial commit"
git push --set-upstream origin master