--- title: About Git rebase redirect_from: - /rebase/ - articles/interactive-rebase/ - /articles/about-git-rebase - /github/using-git/about-git-rebase - /github/getting-started-with-github/about-git-rebase - /github/getting-started-with-github/using-git/about-git-rebase intro: 'The `git rebase` command allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together.' versions: fpt: '*' ghes: '*' ghae: '*' ghec: '*' --- Typically, you would use `git rebase` to: * Edit previous commit messages * Combine multiple commits into one * Delete or revert commits that are no longer necessary {% warning %} **Warning**: Because changing your commit history can make things difficult for everyone else using the repository, it's considered bad practice to rebase commits when you've already pushed to a repository. To learn how to safely rebase on {% data variables.product.product_location %}, see "[About pull request merges](/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges)." {% endwarning %} ## Rebasing commits against a branch To rebase all the commits between another branch and the current branch state, you can enter the following command in your shell (either the command prompt for Windows, or the terminal for Mac and Linux): ```shell $ git rebase --interactive other_branch_name ``` ## Rebasing commits against a point in time To rebase the last few commits in your current branch, you can enter the following command in your shell: ```shell $ git rebase --interactive HEAD~7 ``` ## Commands available while rebasing There are six commands available while rebasing:
pickpick simply means that the commit is included. Rearranging the order of the pick commands changes the order of the commits when the rebase is underway. If you choose not to include a commit, you should delete the entire line. rewordreword command is similar to pick, but after you use it, the rebase process will pause and give you a chance to alter the commit message. Any changes made by the commit are not affected. editedit a commit, you'll be given the chance to amend the commit, meaning that you can add or change the commit entirely. You can also make more commits before you continue the rebase. This allows you to split a large commit into smaller ones, or, remove erroneous changes made in a commit. squashfixupsquash, but the commit to be merged has its message discarded. The commit is simply merged into the commit above it, and the earlier commit's message is used to describe both changes.exec