2

My situation is the following. I've had a git repository set up for me by someone else, and I'm tasked with pushing to the main branch. I started a local React project on a master branch, and I want to push my code to the remote main branch. Here's what I've already done:

git remote add origin <url>
git remote -v
git push origin master:main

I got the following error

! [rejected] master->main (non-fast-forward)
error: failed to push some refs to '<url>'

Whenever I try to run

git push origin main

I get

Everything up-to-date

However, when I check the github repo, none of the changes have been pushed to the main branch. I have no idea how to push the changes and I don't want to do anything irrational on my own. Any help is greatly appreciated.

0

1 Answer 1

3

Try pulling the remote main branch to your local master branch first, this will ensure it's completely up to date, and then you should be able to push it back.

git pull origin master
git push origin master:main

Not the answer you're looking for? Browse other questions tagged or ask your own question.