What is git rebase for?
Git interactive rebase is a way to edit commits in the past. It allows you to choose specific commits to edit, squash, reorder, and delete.
To start an interactive rebase, use the command
git rebase -i HEAD~[number of commits to go back].
You can also use
git rebase -i [commit hash]to specify a specific commit to start the rebase from, instead of using
HEAD~[number of commits].
You can use
git rebase -i [branch name]when you are working with branches, this way you can make sure you are only modifying the commits of the branch you want to modify.
git stashbefore starting an interactive rebase, in case you need to abort the rebase and want to get back to your previous state.
Since 2015, you can use
fixupto combine the changes of a commit with the previous commit.
If you're working with a remote repository, it's better to use
git pull --rebaseinstead of git pull to avoid conflicts when you update your local repository.
Don't stress if you make a mistake during a rebase, you can utilize
git reflogto undo the changes by going back in time 😮
I also suggest you read the Git Pro book.
The cover image was created by deepai.org based on this text: "Git wizard with a long staff in her hand" 😁 🧙♂️