0

I made some changes to some HTML files of my project locally, and am trying to push the changes on my github repository using Git Bash. But it shows the following error

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes

I had changed the name of repository form Github but had then updated it on Git Bash using the command

 git remote set-url origin https://github.com/cyborg7459/bambinos-task1

How to fix this problem?

Cyborg7459
  • 157
  • 3
  • 10
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd Jun 08 '20 at 10:12
  • Either `git pull` or `git push --force` – phd Jun 08 '20 at 10:12
  • Using force push (-f or --force) flag is very dangerous it'll override other commits which are not part of your local changes. Unless you know you are overwriting something intentionally, It should never be part of your regular work flow – Nithish Jun 10 '20 at 03:29

1 Answers1

1

The problem here is the remote repository is having an updated commits by other users which are not available in your local. So what you can do in order to push your local changes to remote is that first pull the changes from upstream to the local, resolve merge conflicts if any and commit and then finally push.

Pull/get the latest changes from upstream

git pull origin <branch>

Push the changes

git push origin <branch>

Note There could be some scenarios where there might be merge conflicts after the pull, then you have to resolve the issues in your local. Stage and commit the changes.

git add .
git commit -m <commit message>
git push origin <branch>
Nithish
  • 5,393
  • 2
  • 9
  • 24