Skip to content

Instantly share code, notes, and snippets.

@iruwl
Last active February 4, 2020 10:22
Show Gist options
  • Save iruwl/8b88384b75781726373c to your computer and use it in GitHub Desktop.
Save iruwl/8b88384b75781726373c to your computer and use it in GitHub Desktop.
Re-initial commit in a Git repository #git

Re-initial commit in a Git repository

Question

How to make the current commit the only (initial) commit in a Git repository ?

Here's the brute-force approach. It also removes the configuration of the repository.

Note: This does NOT work if the repository has submodules! If you are using submodules, you should use e.g. interactive rebase

  1. Remove all history

    rm -rf .git
    
  2. Reconstruct the Git repo with only the current content

    git init
    git add .
    git commit -m "Initial commit"
    
  3. Push to GitHub.

    git remote add origin <github-uri>
    git push -u --force origin master
    
  4. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment