Jump to content

How to Git Rebase One Branch on Top of Another Branch


Recommended Posts

In Git, when users want to combine the commit history of two branches without merging it, the “git rebase” command can be used. The rebasing operation pushes the commits history of one branch at the top of another local branch, and the HEAD pointer moves to it. Basically, it temporarily rewinds the commits on their current working branch.

This study will discuss the method of rebasing one local branch on top of another.

How to Perform Rebase On One Git Branch on Top of Another?

Follow the below-given procedure to rebase Git one branch on top of another branch:

Step 1: Switch to Git Local Repository

First, move to the particular Git repository by providing its path in the “cd” command:

$ cd "C:\Users\nazma\Git\perk3"

Step 2: Show Remote URL List

Then, run the following command to check the remote URL list:

$ git remote -v

123-1.png

Step 3: Download Latest Version of Remote Repository

To download the copy of the updated version of the remote repository, use the “git fetch” command:

$ git fetch

123-2.png

Step 4: View List of Local and Remote Branch

After that, execute the “git branch” command to get the list of local and fetched remote branches:

$ git branch -a

Here, the “-a” option represents all. It can be seen that all branches are displayed, and we have selected the “alpha” branch for further process:

123-3.png

Step 5: View Log History
Now, check the list of the Git repository log history through the “git reflog .” command:

$ git reflog .

123-4.png

Step 6: Rebase Particular Branch

Finally, use the “git rebase” command along with the remote name and selected local branch:

$ git rebase origin/alpha

According to the below-given output, the rebasing is performed successfully:

123-5.png

Step 7: Ensure Rebasing Operation

Lastly, execute the below-stated command to verify the rebasing operation:

$ git reflog .

It can be seen that the “alpha” branch commit is rebased on top of the other branch commit history:

123-6.png

That’s all! You have learned how to rebase one Git branch on top of other local branches.

Conclusion

To rebase Git one branch on top of another branch, first, move to the particular repository. Then, check the remote URL list and download a copy of the updated remote repository. Next, list all the branches, including both remote and local. Now, check the reference log history and execute the “git rebase <remote-name>/<local-branch-name>” command. This study illustrated the method of rebasing one local branch on top of another.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...