Skip to content

Cleaning up a Pull Request with Rebasing

Joel Meador edited this page Jun 8, 2026 · 1 revision

I started a new branch and submit a PR to merge back into the main branch. There are a lot of extra commits that I would like to clean up before merging, in addition to getting the branch up to date with the latest.

How do I go about cleaning up this branch? What are the steps to rebase and clean up a working branch, after submitting a pull request, before merging with the main branch?

Given you are on some branch, "branchname" for later use.

After submitting your pull request, with your working branch checked out, run

git rebase -i main

(or substitute the branch you want to rebase to for "main" if you are rebasing to a different branch)

You'll get a prompt in your editor showing a list of all of your commits and a list of actions for each commit, including:

  • pick, use this as-is
  • reword, change the commit message
  • squash, ditch this commit record, merge these changes into the commit above

At a minimum you need to leave the first commit set to pick - you'll get an opportunity to reword it at the end of the rebase process.

When you're done setting the various commits to pick / reword / squash etc, save and close; now you'll get the prompt to make any changes to the commits you're keeping. Helpfully, the message for each commit that's being squashed in will be shown in each prompt.

After you've made any changes for the remaining commits, saved and closed, you're ready to push your changes up:

git push --force-with-lease origin branchname

If you are looking at the pull request in the GitHub web view, you should see the cleaned up commits after refreshing the PR page; now your branch is cleaned up and ready to merge.

Reference:

Eric's Git Parkour Tour

How to squash commits

Home

TODO: can we recreate the tag system here roughly with sections about certain subjects?

Clone this wiki locally