Rebasing
Rebasing means changing the old base of the branch to a new one built on the top of the master/main branch. It also allows you to change individual commits.
#
Command
Description
1
git rebase [new-base]
Change the old base to the [new-base] (include all changes that were done in the main branch or a commit ID). It is similar to merge, but this will include all commits history.
2
git rebase -i main
Option -i means interactive. This lets you edit the list of commits that are about to be rebased. You can condense two commits in one - use squash or edit to make some amendments - this basically pauses the rebase. For example, you can add your change to staging and next to include it in your edit commit use git commit --amend to replace the commit message.
3
git rebase --continue
This is the last step to do after the command above.
4
git rebase --abort
When you are in the middle of rebasing and you are not sure if you should continue, you can use --abort flag to discard changes and start from scratch.

Example

1
// Start rebase, to add changes from the development branch (make sure to pull it first and back-up your feature branch):
2
​
3
git rebase development
4
​
5
# if there are any conflicts - fix them and save the file, next add your changes with:
6
git add .
7
​
8
# continue rebase
9
git rebase --continue
10
​
11
# after successful rebase push your changes with force, two options here:
12
# 1. Force with lease - recommended option - this prevents overwriting commits somene has pushed up in the meanitme
13
git push --force-with-lease
14
​
15
# 2. Just force
16
git push --force
Copied!
Copy link
Contents
Example