Refactor Git branch

Enable Javascript to display Table of Contents.

Interactive Rebaseing

To refactor git commits, you have to call git rebase -i against the branch you have branched from (e.g. master):
$ git rebase -i master
Then a text editor opens and allows you to modify the commits you have:
pick 916edcc Expose i40e GPIOs/SDPs and allow to set each individually
pick 70c1438 Add linuxptp to packagegroup-bh
pick ba46555 Add configuration for linuxptp
pick fe2a22b Add systemd services for linuxptp
pick 8aa2877 Fixing GPIO handling

# Rebase 1455cd7..70c1438 onto 1455cd7 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
By moving the lines or replacing the pick command, you can modify your branch history. After working on the file, it can look like this:
pick   916edcc Expose i40e GPIOs/SDPs and allow to set each individually
fixup  8aa2877 Fixing GPIO handling
reword ba46555 Add configuration for linuxptp
fixup  fe2a22b Add systemd services for linuxptp
pick   70c1438 Add linuxptp to packagegroup-bh
It results in 3 commits:
$ git log --oneline | head -n3
70c1438 Add linuxptp to packagegroup-bh
ba46555 Add configuration and systemd services for linuxptp
916edcc Expose i40e GPIOs/SDPs and allow to set each individually
$
I personally use the interactive rebase for After that, you have to push the branch with --force, since the branch history has changed:
$ git push -f
Source: stackoverflow