I use a combination of these 2 articles to collapse my Git history : Collapsing a git repository's history and Combine the first two commits of a Git repository?
This is the result
git rebase -i THE_SHA_1_OF_FIRST_COMMIT
# change "pick" into "squash" for all commits except first one
# :wq (if your editor is vi)
git rebase -i THE_SHA_1_OF_FIRST_COMMIT
# change "pick" into "edit"
# :wq (if your editor is vi)
git reset --soft HEAD^
git commit --amend
git rebase --continue
# garbage collect
git reflog expire --expire=1.minute refs/heads/master
git fsck --unreachable
git prune
git gc
This work great but as I use this quite often, I wish to automatize this in a script. The problem is some commands like "git rebase -i" open a file to edit and I have to do it manually (same problem for "git commit --amend"). Is there a way to automatize this process? I'm not asking for a solution ready to use, just the idea.