title: Updates were rejected because the remote contains work that you do not have locally
body: <p>I'm working on a team with a few developers using git on BitBucket. We are all working on a <code>dev</code> branch, not pushing to <code>master</code> until a release.</p>
  <p>One of the developers committed incorrect code that overwrote my own by accident, and now I am trying to push the correct code  back to the repo. I have been reading about this error for a few days now, I can't push to the repo anymore because I am getting the following error:</p>
  <pre><code> ! [rejected]        master -&gt; dev (fetch first)
  error: failed to push some refs to 'https://myusername@bitbucket.org/repo_user/repo_name.git'
  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.
  </code></pre>
  <p>I follow the instructions and <code>pull</code>, but then I receive a merge conflict. After entering a message for the merge conflict, my local code is now the incorrect code that the other developer uploaded by accident (as expected from the <code>pull</code>). So I replace the incorrect code with the backup I copied before committing, and when I try to push again, I get the same error.</p>
  <p>It is really frustrating, I really want to help out my team and contribute, but I can't because of this error. Does anyone know how to solve this issue? I would very much appreciate any help.</p>
  <p>These are the commands I run in order to commit if it helps anyone out:</p>
  <pre><code>git pull remotename master:dev
  git add --all
  git commit -m &quot;some message&quot;
  git pull remotename master:dev
  git push remotename master:dev
  </code></pre>
  <p>I would have thought that if I kept this order, I would not receive merge conflicts. I guess I was wrong. Thanks again</p>
  <p>Update:
  I should add that I have looked for a few hours on Google and StackOverflow, and followed different instructions, but I still can't <code>push</code> to the <code>dev</code> branch.</p>