git: Your branch and 'origin/somebranch' have diverged - how to throw away local commits

Paulo Victor picture Paulo Victor · Sep 17, 2015 · Viewed 43.4k times · Source

I have a question that most closely matches my problem was made, but could not add a comment.

git: Your branch and 'origin/master' have diverged - how to throw away local commits?

I ran the tips and answers to the question above, but nothing decided. I am following with a progress chart using the sofwae source tree. I close the software and run the commands in the bash git. But there is the same mistake quoted.

# Your branch and 'origin/master' have diverged,
# and have 7 and 11 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)

I am also facing the same problem. follow the steps running 2 comentos but not worked. I think my problem is that before I made a checkout for a indiividual head, made a commit in individual head and then I went back to the tree branch / master, and commit that I did, I believe that references the tree head individual. In summary I can not undo this commit, I'm displayed graphically on SourceTree software

EDIT - ADD INFORMATION: I'd like to throw out of the unpublished commits and make server checkout. But the solutions I found an internet not working. I also tried git reverse in gitBash the console displays the message that I do deveo

$ Git status
On branch processos_criminais_151029
Your branch and 'origin / processos_criminais_151029' have diverged,
and 7 and 11 have different commits each, respectivamente.
   (use "git pull" to merge the remote branch into yours)

Changes not staged for commit:
   (use "git add <file> ..." to update what will be committed)
   (use "git checkout - <file> ..." to discard changes in working directory)

I tried the two solutions but none worked. If I try and push gives the conflict a huge amount of files, and I tried to solve these problems with the automatic merge, but to make a new git status he points out that the same quantidde files are conflicts.

Answer

poke picture poke · Sep 17, 2015

Your branch and 'origin / processos_criminais_151029' have diverged

So of course, resetting to origin/master will not work. You will have to reset to that remote branch in order to reset your local branch to it.

So the commands you need to run are this:

git fetch origin
git reset --hard origin/processos_criminais_151029