In software development, managing commits is essential for maintaining a clean and coherent project history. Git offers various tools to manage commits, including rebasing, which allows you to reapply commits on top of another branch's history. Let's explore how to rebase commits effectively.
- Create a branch called
feature-branch
. - Make several commits in the
feature-branch
to simulate a feature development process. - Switch to the master branch
- Make some commits into the
master
branch
Now, let's assume that while you were working on your feature, changes were made to the master
branch. To incorporate these changes into your feature branch, you can rebase your commits onto the latest master
branch.
- Switch to the
feature-branch
by runninggit checkout feature-branch
. - Run
git rebase master
to rebase your commits onto the latestmaster
branch.
After resolving conflicts, continue the rebase process by running git rebase --continue
.
Once the rebase is complete, your commits will be applied on top of the latest main
branch.
After rebasing and squashing commits, you can push your changes to the remote repository and create a pull request for review.