AWS Logo
Menu

Fail to push code existing repo code in the GitHub main branch

Here I share with you how to push code in GitHub and to push code existing repo main branch.

Published Jan 15, 2025

How do you push code in the GitHub main branch?

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Your_name/project_name.git
git push -u origin main

Where did you get the origin link?

Open the repository and copy the top bar address or you can copy it here. Please see the screenshot

How do you push an existing repository from the command line?

  • 1st Method
git remote add origin https://github.com/Your_name/project_name.git
git branch -M main
git push -u origin main
  • 2nd Method
git init
git add .
git commit -m "message"
git rebase --continue
git remote add origin https://github.com/Your_name/project_name.git
git branch -M main
git push -u origin main
If it still does not work please use the Amazon Q Developer vs code plugin to solve this problem.
Learn more: Amazon Q Developer
I think it will work perfectly. Thank you.
 

Comments