git - resetting a remote repository

It can sometimes be useful to remove the commit history for a project that is under git. and basically make the latest state be the first commit. An example use case might be when uploading to github.

However, if other folk are using the bare repo, then you need to let them know what you are doing.

The process is not at all complex. But first, ensure you have a backup copy of your project somewhere safe.

  1. cd project_directory
  2. mv .git/config ~/saved_git_config
  3. rm -rf .git
  4. git init
  5. git add .
  6. git commit -m 'Initial commit'
  7. mv ~/saved_git_config .git/config
  8. git push --force origin master

If you instead, or also, want to push to github (or somewhere else) then do something like this:

  1. git remote add github
  2. git config branch.master.merge refs/heads/master
  3. git push -u github master