Rebasing with git

a minute read

Git makes working on a project flexible by allowing teams to work in parallel and concurrently. When a team’s work is done, they can bring their work on to the main public branch either by rebasing it or merging it.

Lets take for example two commits from two different branches, live and staging. We assume that both branches have a common snapshot.

For example,

– the staging branch commit history is:

Commit A
Commit C
Commit D

while the

– live branch commit history is :

Commit A
Commit B


Both branches have a common snapshot in history according to their commit histories.


If we would like to rebase the work that now exits on live, onto our staging branch. We will have to :

git checkout staging

git rebase live


This operation will go to the common ancestor for both branches (the live and the staging). It will get the commit history of the staging branch and save the diffs to temporary files. It will then reset the staging branch to the same commit history as the live branch, i.e staging will now be fast forwarded to the commit B snapshot. It will then apply the commits of the staging branch which were previously copied to a temporary files on top of that.

This will simply fast forward the staging branch, with all the changes that were made on the live branch. This really makes your commit history clean and as if the changes were made in sequence while in reality they changes could have happened in parallel.

Keeping the history clean for a remote / public branch is important. It removes any need for additional work and the branch only needs to fast-forward to bring the changes forward.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket


No comments

Related Posts:

To initialize a Git repository in a new project, follow these steps:Open your project directory in a terminal or command prompt.Initialize a new Git repository by running the command: git init.This will create a hidden .git directory, which contains all the ne...
Creating and applying Git tags is a useful way to label specific points in a Git repository's history. Tags can be used to mark significant versions or milestones in a project. Here's how you can create and apply Git tags:Creating a Git tag: To create ...
Git hooks are scripts that can be executed automatically whenever certain actions occur in a Git repository. By using Git hooks, you can automate various tasks and enforce certain workflows in your development process.To use Git hooks for automation, follow th...
To clone a subset of Git branches, you can follow these steps:Open a terminal or Git bash.Navigate to the directory where you want to clone the repository.Clone the repository using the git clone command followed by the repository URL: git clone <repository...
To delete the merge history of a file in Git, you can follow these steps:Open a terminal or Git Bash and navigate to the directory of your Git repository. Use the git log --follow command to view the complete history of the file, including merge commits. Make...
To commit changes to a Git repository, you need to follow these steps:Add files to the staging area: Use the command git add to add specific files or git add . to add all modified files to the staging area. This prepares them for the commit. Check the status:...