Last active
July 12, 2026 16:04
-
-
Save keesiemeijer/b17a8663815b51a472561f0fe9b385dc to your computer and use it in GitHub Desktop.
Gir Rebase to merge commits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Full Rebase Checklist (Vim) | |
| To reword a specific commit message, or merge multiple commit messages in to one start an interactive rebase by running git rebase -i HEAD~n, where n is the number of commits back from HEAD you want to edit. | |
| Then | |
| - change `pick` to `reword` (or `r`) for the commit you want to modify | |
| - change `pick` to `squash` (or `s`) for the commits you want to squash | |
| `pick` simply means that the commit is included in the rebase. pick the oldest commit to merge newer commits into. | |
| 1. **Start the rebase:** | |
| ```bash | |
| git rebase -i HEAD~3 | |
| ``` | |
| 2. **Select your actions:** | |
| * Press `i` to enter **Insert Mode** (you will see `-- INSERT --` at the bottom). | |
| * Use arrow keys to find your target commit. | |
| * Change the word `pick` to `reword` (or `r`), or `squash` (or `s`). | |
| * Press `Esc` to exit Insert Mode. | |
| * Type `:wq` and press `Enter` to save and exit. | |
| 3. **Update the commit message:** | |
| * A new screen opens with your old commit message. | |
| * Press `i` to enter **Insert Mode**. | |
| * Use arrow keys to navigate, delete the old text, and type your new message. | |
| * Press `Esc` to exit Insert Mode. | |
| * Type `:wq` and press `Enter` to save and exit. | |
| 4. **Verify completion:** | |
| * Your terminal should print: `Successfully rebased and updated...`. | |
| 5. **Run the safe force push command:** | |
| Always use `--force-with-lease` instead of `-f`. This prevents you from accidentally overwriting a teammate's work if they pushed new commits while you were rebasing. | |
| ```bash | |
| git push origin <your-branch-name> --force-with-lease | |
| ``` | |
| 6. **Alternative (If you are the only one working on the branch):** | |
| If you are absolutely certain no one else has touched the branch, you can use the standard force flag: | |
| ```bash | |
| git push origin <your-branch-name> -f | |
| ``` |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full Rebase Checklist (Vim)
To reword a specific commit message, or merge multiple commit messages in to one in Git use Rebase.
Start an interactive rebase by running
git rebase -i HEAD~n, where n is the number of commits back from HEAD you want to edit.picktoreword(orr) for the commit you want to rewordpicktosquash(ors) for the commits you want to mergepicksimply means that the commit is included in the rebase. Pick the oldest commit to merge newer commits into.Start the rebase:
Select your actions:
ito enter Insert Mode (you will see-- INSERT --at the bottom).picktoreword(orr), orsquash(ors).Escto exit Insert Mode.:wqand pressEnterto save and exit.Update the commit message:
ito enter Insert Mode.Escto exit Insert Mode.:wqand pressEnterto save and exit.Verify completion:
Successfully rebased and updated....Run the safe force push command:
Always use
--force-with-leaseinstead of-f. This prevents you from accidentally overwriting a teammate's work if they pushed new commits while you were rebasing.Alternative (If you are the only one working on the branch):
If you are absolutely certain no one else has touched the branch, you can use the standard force flag: