Late 2021 update
GitHub changed authentication flow some time in August of 2021. I was having the same problem and managed to push a new project into GitHub by following these steps:
echo "# REPO_NAME" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://USERNAME:[email protected]/USERNAME/REPO_NAME.git
git push -u origin main
The origin URL must have the username followed by an access token.
You can generate the ACCESS_TOKEN
by going to Github > Settings > Developer Settings > Personal access tokens > Generate new token
. Give it a name and make sure you select Repo in Select Scopes.
Personally I think this is overkill. Tokens expire and now I have to manage tokens for each project that I work on. Maybe there is an easier way, I don't know but I hope so. My VS Code is already authenticated with Github, why complicate things. Maybe someone can show a easier way to go about it.