Git create branch from another branch for comparision

In here I showed you, how you can rename a branch.

Sometimes you come across a situation where you reset the head of a branch but another developer merged in the old version (with multiple subsequent merges from PR´s that you wanted to remove).

One way to solve this is to rebase. But sometimes this doesn´t work as expected. Then this could help:

Checkout the branch

git checkout $branch_name

Reset your head until you are before the merge (use –mixed to conserve the changes in your working tree)

git reset Head~1 –mixed

Create new branch

git checkout -b $new_branch_name

Apply your changes and commit

Compare your braches

git diff $old_branch_name $new_branch_name

If you need to push to your remote and the configuration for the new branch is still on the old remote branch, you find how to fix it here: here.

Let me know if it helped you.

Best,

Frank

Leave a Reply