24

I have a brand new git repo. It has three commits.

I'd like to squash them together so my project history looks clean, and others don't see my hacky commits.

Obviously nobody else has seen the repo, as it's brand new, so changing history is not a problem. I am the only user.

However git rebase -i wants me to track an upstream branch. I don't want to publish anything until I've tidied up the git log.

How can I do a interactive rebase, or squash commits in general, without tracking an upstream?

1 Answer 1

26

You can skip tracking a remote branch by specifying the last n commits you want to squash.

For eg. if you have 4 commits in your branch and you want to squash the last 3 commits effectively making a single commit, you can do git rebase -i HEAD~4. You can then either fixup or squash the commits as you wish.

1
  • 21
    useful: git rebase -i --root
    – Regisz
    Commented Nov 8, 2016 at 14:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.