1
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
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Hi I am new to git, so we are working on a project in our office, we are using bitbucket. I have committed and pushed some lines of code. To the same PR, another person has pushed their code. How can I pull their code to my local repo?

I didn't update my code with theirs and when I tried to push my code I got the above error. Upon force push, their commit was overridden.

Sindhu
  • 29
  • 1
  • 3

2 Answers2

2

Never force anything, especially if you don't know what you are doing. That said, the right thing for you to do was to pull their work with git pull [remote] [branch], fix any merge conflicts, commit and push your code. Now, that you have force pushed your code and your friend's commit does not exist on the remote, your friend has to do the exact same thing

  1. git pull [remote] [branch]
  2. Fix merge conflicts. Git would warn you if there are any
  3. Commit if there were any merge conflicts with git commit
  4. git push [remote] [branch]

Then you can do a git pull [remote] [branch] and everything would be in sync.

Sanil Khurana
  • 1,129
  • 9
  • 20
0

You have to run git pull first to download and merge the changes that are already made to the repository into your local clone of the repository.

It could be that you get a so call merge conflict when doing this. That happens when some code that you changed no longer exists or was changed already in the main repository.

If you encounter a merge conflict you can find help here:

https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts

MarvinJWendt
  • 2,357
  • 1
  • 10
  • 36