2

Possible Duplicate:
master branch and 'origin/master' have diverged, how to 'undiverge' branches'?

I googled and read many posts, but none could make me understand the branch divergence problem yet.

If I've remote tracking branch, I often get into the following:

$ git status
# On branch feature/worker-interface
# Your branch and 'origin/feature/worker-interface' have diverged,
# and have 1 and 4 different commit(s) each, respectively.

Can anyone have any good and clear advice or point into good post about this git issue?

Community
  • 1
  • 1
millisami
  • 9,931
  • 15
  • 70
  • 112

1 Answers1

1

First, you can use the cherry command to see what commits differ between branches, and in what ways. So in this case, running git cherry origin/feature/worker-interface shows us the status of commits on the current branch and how they stack up against origin/feature/worker-interface. You will find 1 repo which you forgot to commit.

Now, lets see whats happening with the 'origin/feature/worker-interface' and its commits.For this we can run a log command with a special format git log ..origin/feature/worker-interface --oneline

Here we see 4 commits that don't exit in our current branch

So now we have a good idea of what’s happened. you’ve made 1 commits on your local master branch, and it looks like there are 4 commits on origin/feature/worker-interface which you don’t have merged in yet. So, you could just blindly merge things together and go on your way (if they merge without conflict), but I’d like to show you how to deal with it in a more controlled manner.

  1. First, create a branch that points to your current HEAD: git checkout -b local_changes
  2. Now that we have that to keep track of those changes, we switch back to feature/worker-interface: git checkout feature/worker-interface
  3. At this point, reset the feature/worker-interface branch to get rid of the 1 commit.
  4. There you go! You can check your status of branch git status you will be prompted as nothing to commit
kmort
  • 2,848
  • 2
  • 32
  • 54
uday
  • 8,544
  • 4
  • 30
  • 54