Skip to content
Discussion options

You must be logged in to vote

Make sure your branch is up to date with the main (or your base branch).
2. Run:

git rebase -i HEAD~N

Replace N with the number of commits you want to squash (for example, if you want to squash your last 3 commits, use HEAD~3).
3. In the interactive editor that pops up, keep "pick" for the first commit and change "pick" to "squash" (or "s") for the others you want to combine.
4. Save and close the editor.
5. Git will open another editor to combine commit messages. Edit as desired, then save and close.
6. Push your changes with force:

git push -f origin your-branch-name

Now your commits are squashed into one!

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Thisath345
Comment options

Answer selected by Thisath345
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pull Requests Propose, review, and discuss changes to a repository's codebase Question Ask and answer questions about GitHub features and usage
3 participants