DEV Community


Using VS Code to git rebase

Colby Garland
Software Engineer, passionate about TypeScript, Flutter and Mobx-state-tree.
・2 min read

Git rebase is a powerful, albeit confusing tool. I primarily use rebase to squash my commits before I PR my branch into main. This tutorial will show you how to use VS Code to visually do this process.


You will need to install this VS Code extension:

You will also need to enable "force push":

In settings, search for "git allow force push" and check the box


Optional but recommended: set VS Code as your git editor:

git config --global core.editor "code --wait"

Let's Begin!

  1. Ensure your local branch you are rebasing onto (in our case, main) is up to date.
  2. Switch to your feature branch (the branch you have been working on)
  3. Type in git rebase -i main, where main is the branch you are rebasing onto
  4. You will then see the codelens rebase screen, where you can choose what to do with each commit. We are going to squash every commit, and reword the last one into a good commit message.
  5. Once you have your commits ready, we can click the Start Rebase button.
  6. You will then be presented with a screen in VS Code to reword your commit message. Write your new message, and save and close the file to continue.
  7. After this, our rebase is complete. However, now we must force push to remote. In your version control panel, click on the kebab menu (3 dots) and under the Pull, Push menu, choose Push (Force). Use this with caution, especially when working with other developers, as force push is destructive.

And we are done! A very easy way to rebase and squash all your commits using VS Code.

Discussion (1)

bdougherty profile image
Brad Dougherty

Wouldn't it be easier to do a squash merge instead? git merge --squash [branch]