Skip to content

Instantly share code, notes, and snippets.

@keesiemeijer
Last active July 12, 2026 16:04
Show Gist options
  • Select an option

  • Save keesiemeijer/b17a8663815b51a472561f0fe9b385dc to your computer and use it in GitHub Desktop.

Select an option

Save keesiemeijer/b17a8663815b51a472561f0fe9b385dc to your computer and use it in GitHub Desktop.
Gir Rebase to merge commits
### 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
```
@keesiemeijer

keesiemeijer commented Jul 12, 2026

Copy link
Copy Markdown
Author

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.

  • change pick to reword (or r) for the commit you want to reword
  • change pick to squash (or s) for the commits you want to merge

pick simply means that the commit is included in the rebase. Pick the oldest commit to merge newer commits into.

  1. Start the rebase:

    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.

    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:

    git push origin <your-branch-name> -f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment