DEV Community

Discussion on: Squashing commits in Git!

Collapse
 
recursivefaults profile image
Ryan Latta

You only need to force push when you have to overwrite a remote's history of commits. If you only rebase commits that you've not pushed, you'll find you never have to force push.

Give it a try. Make a bunch of commits without pushing them. Do your interactive rebase on ONLY those commits. You'll have no problem pushing because you'd be pushing 1 squash commit. The remote repo never knew or cared you have others before the rebase. When you rebased you rewrote that history to never exist. When you push it looks like you only ever had 1 commit.

For fun clone the repo somewhere else. and do it again only this time do a few commits, and push them one at a time. Somewhere in the middle of pushing pull to your 2nd repo. Add a few commits in that 2nd repo. Go back to your original and squash those commits and force push. Go to your 2nd repo and do a pull. See what happens.

Knowing how this works will be a pretty important thing. Someone you work with will mess up a repo at some point. Good to know how it looks and how to fix it. Its a super power.