Git: How to squash all commits on branch

I make new branch from master with:

git checkout -b testbranch

  • Heroku Zbar Didn't find libzbar on your system (LoadError)
  • Is there a way to make git remember the password for WebDAV remotes?
  • Setting git default flags on commands
  • Git Checkout and Pull through Lib2GitSharp
  • Deploy path doesn't work for Git Deploy Method in middleman-deploy
  • Suse Enterprise 11 SP2 how to install git
  • I make 20 commits into it.

    Now I want to squash those 20 commits. I do that with:

    git rebase -i HEAD~20

    What about if I don’t know how many commits? Is there any way to do something like:

    git rebase -i all on this branch

  • git merge -s recursive -X ours vs git merge -s ours?
  • removing local git repositary from Xcode Project?
  • Xcode can't verify the identity of the server “”, Xcode
  • Recommended way to use Autoconf Archive macros and other 3rd party macros
  • Mac specific optimizations in ~/.gitconfig
  • GIT Server install failing on Ubuntu
  • 3 Solutions collect form web for “Git: How to squash all commits on branch”

    Another way to squash all your commits is to reset the index to master:

     git checkout yourBranch
     git reset $(git merge-base master yourBranch)
     git add -A
     git commit -m "one commit on yourBranch"

    This isn’t perfect as it implies you know from which branch “yourBranch” is coming from.
    Note: finding that origin branch isn’t easy/possible with Git (the visual way is often the easiest, as seen here).

    What you’re doing is pretty error-prone. Just do:

    git rebase -i master

    which will automatically rebase only your branch’s commits onto the current latest master.

    Another simple way to do this: go on the origin branch and do a merge --squash. This command don’t do the “squased” commit. when you do it, all commit messages of yourBranch will be gathered.

    $ git checkout master
    $ git merge --squash yourBranch
    $ git commit # all commit messages of yourBranch in one, really useful
     > [status 5007e77] Squashed commit of the following: ...
    Git Baby is a git and github fan, let's start git clone.