Git

Rebase Feature Branch Onto Another Feature Branch

When developers work on extensive development projects, they create different branches and work on them to avoid a mess. After completing their work in the desired branches, the changes are integrated from one branch to another. For this corresponding purpose, the rebase operation can be performed. It applies the commits from one Git branch on top of another target branch.

This write-up will demonstrate the process of rebasing the feature branch into another feature branch.

How to Rebase the Feature Branch Onto Another Feature Branch?

To rebase the feature branch onto another feature branch, follow the provided steps:

  • Switch to the desired repository.
  • List Commits of the current working branch.
  • Move to another branch and view its commit history.
  • Perform the rebase operation.
  • Verify added changes.

Step 1: Redirect to Local Directory

First, navigate to the particular repository with the help of the below-stated command:

$ cd "C:\Git\new_repos

Step 2: Check Git Log

Then, view the commit history to check the recent commits of the current branch:

$ git log --oneline

The below-provided output indicates that there are three commits and the HEAD is pointing to the β€œDemo File added” commit:

Step 3: View Available Branches

Next, use the β€œgit branch” command to view the list of all available branches:

$ git branch

Here, it can be observed that there are two branches in the repository and the asterisk β€œ*” symbol with the β€œmaster” branch shows that it is the current branch:

Step 4: Switch to Another Branch

Now, move to the β€œalpha” branch using the β€œgit switch” command:

$ git switch alpha

Step 5: View Commit History

Run the β€œgit log” command to check the Git log reference of the current branch:

$ git log --oneline

It can be seen that there are four commits in the branch and the HEAD is pointing to the β€œfile2 updated” commit:

Step 6: Perform Rebase Operation

Now, rebase the β€œmaster” branch onto the target branch named β€œalpha” by running the following command:

$ git rebase master

According to the below-provided output, the rebase operation has been performed successfully:

Step 7: Verify New Changes

Lastly, check the Git log to view the newly added changes in the commit history:

$ git log --oneline

As you can see, the rebase operation has moved the β€œalpha” branch commits to the β€œmaster” branch commits:

That’s it! We have efficiently explained the process of rebasing from one feature β€œmaster” branch into another feature β€œalpha” branch.

Conclusion

To rebase a feature branch into another feature branch, first, redirect to the required repository and check its Git log reference history. Then, navigate to another branch and check its commit history. After that, execute the β€œgit rebase <branch-name>” command to perform the rebase operation. Lastly, verify the new changes. This write-up described the easiest way to rebase the feature branch into another feature branch.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.