Home > Mobile >  git merge parent branch in child branch not working
git merge parent branch in child branch not working

Time:10-07

I have parent branch A and child branch B. There were few commits in A.

I tried below commands to update my B with A.

git pull origin A

then

git checkout A
git pull
git checkout B
git merge A

For first command I got merge conflicts which i resolved and pushed my changes. But all of the changes of A was not getting reflected in B.

for second and third command I tried and got result as Already up to date.

How to update B with all changes of A

CodePudding user response:

TL;DR Your first operation completed the merge you are still trying to do in the last operation.

Details

To understand what's going on, let's replace git pull by its equivalent two step commands: each time you run git pull, what you're really doing is git fetch followed by git merge.

So, in step 1, you effectively did:

git fetch origin
git merge A  #(almost, see below)

Assuming you were on branch B at the time, the conflicts your resolved and committed merged A into B.

(#almost: it actually does git merge origin/A, but creates a default commit message saying "merge A" rather than "merge origin/A". In your case, step 2 confirms A was already up to date, so this detail would have made no difference)

In step 2, you effectively did

git checkout A
git fetch
git merge

Now by default that git fetch fetches from origin, which you'd already done in step 1. And that git merge saying Already up to date just means that your A branch was already up to date with origin at the time, since the default is to merge origin/<my-current-branch> into <my-current-branch> when you run git merge (or git pull) without an argument.

In step 3, you just tried to redo the merge you have already completed in step 1:

git checkout B
git merge A

so it's no surprised B is already up to date with respect to A.

Inspecting your commit graph

When I'm trying to figure out what's going on in my sandbox, I always use a tool that shows me my whole commit graph visually, with all branches.

Here's a simple command line to do that, but all visual commit graph viewer have the option to show all branches:

git log --graph --format=oneline --all --decorate

If you run that after each operation, the state of things should be fairly obvious.

PS: My favourite git log command is actually this one, which I've aliased to git loga in my .gitconfig:

git log --color --graph --all --format=format:"%Cred           
  • Related