Git Rebase using Tortoise GIT

Git Rebase using Tortoise GIT

Wy should you rebase your code before commit?

https://www.atlassian.com/git/tutorials/merging-vs-rebasing Check this article!

I am using Tortoise GIT for my exercise. Here is sample of 'Logs' for code base that does not do rebase.

Change history messed up making it hard to get clarity on branch history. On close inspection, one would most likely observe same commit is appearing more than once in history due to strategy of 'merge from master' and proceed.

No alt text provided for this image


Here is sample 'Logs' from code base that mandates rebase by developers.

No alt text provided for this image

How to Rebase?

First step of course is to identify if feature branch requires rebase. Feature branch should start from the tip of master. I usually see SHA signature to find this out.

This is how I rebase using Tortoise GIT. In case if you are nervous, create copy of branch :)

Get Your 'main' branch up-to-date

  • Commit and push changes to feature branch.
  • Fetch contents from remote.
  • Switch to master or main branch. Pull latest changes from remote. Hopefully no one pushes when you are doing below exercise.

No alt text provided for this image

Time to Rewrite History of Feature Branch

  1. Switch to feature branch.
  2. Use context menu and select 'rebase'.

No alt text provided for this image

Make sure settings are right. Check high lighted sections below.

No alt text provided for this image

Click on start rebase, and there might be conflicts. You can 'Pick' or 'Skip' specific change.

No alt text provided for this image

If everything goes fine, 'Done' screen should come.

No alt text provided for this image

Now time to 'Push' changes to remote.

No alt text provided for this image

That is all :)

To view or add a comment, sign in

Others also viewed

Explore content categories