DEV Community

Jhutan Da
Jhutan Da

Posted on

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

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 description
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

I think it will work perfectly. Thank you.

Top comments (0)