Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git basics
  6. Managing Git history
  7. Rebasing commits
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Rebasing commits

Rebasing in Git is a process that allows you to move or combine a sequence of commits to a new base commit. This can be particularly useful for integrating changes from one branch into another cleanly.

When to use rebasing:

  • Updating feature branches: When your feature branch has fallen behind the main branch, you can rebase it onto the latest main branch to bring it up to date. This results in a linear commit history without merging commits.
  • Cleaning up commit history: Before merging a feature branch into the main branch, you can use interactive rebasing to squash commits, reorder them, or edit commit messages, creating a more cohesive and readable commit history.
  • Avoiding merge commits: When you want to incorporate changes from another branch without adding merge commits, rebasing can apply those changes directly to your branch.
Diagram of identifying a commit to rewrite. Diagram of identifying a commit to rewrite.

Identify the commit you want to rewrite and run the git rebase -i command.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life