Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

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
Image not found

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

Log in to comment