Git root empty commit

The best way to structure yout repository is to have an empty root commit and to squash all the other commits periodically onto the second. This reduces the repository size making it easier to clone in CI and for your end users.

Empty root commit Link to heading

Create an empty commit:

git commit -m 'Initial commit' --allow-empty

Rebase until your root commit:

git rebase -i --root

Move the last commit at the very top of your commit list.

Clean history Link to heading

Rebase until your root commit:

git rebase -i --root

Now you do the follwoing changes:

  1. Mark your second commit from the top from pick to reword.
  2. Vertical select and change all other commits from line 3 downwards from pick to fixup.

Result Link to heading

After this you will be left with 2 commits:

  • An empty initial commit
  • A second commit that contains the entire diff up to this point.

Now your repository is properly nice an clean, like it’s supposed to be.