gitversion-control

Git: How to reset a remote Git repository to remove all commits?


How can I reset a remote and local Git repository to remove all commits?

I would like to start fresh with the current Head as the initial commit.


Solution

  • Completely reset?

    1. Delete the .git directory locally.

    2. Recreate the git repostory:

      $ cd (project-directory)
      $ git init
      $ (add some files)
      $ git add .
      $ git commit -m 'Initial commit'
      
    3. Push to remote server, overwriting. Remember you're going to mess everyone else up doing this … you better be the only client.

      $ git remote add origin <url>
      $ git push --force --set-upstream origin master