Reputation: 14433
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.
Upvotes: 214
Views: 203866
Reputation: 46
You can use this command instead of deleting .git
file
git remote remove origin
Upvotes: 0
Reputation: 2180
Were I you I would do something like this:
Before doing anything please keep a copy (better safe than sorry)
git checkout master
git checkout -b temp
git reset --hard <sha-1 of your first commit>
git add .
git commit -m 'Squash all commits in single one'
git push origin temp
After doing that you can delete other branches.
Result: You are going to have a branch with only 2 commits.
Use
git log --oneline
to see your commits in a minimalistic way and to find SHA-1 for commits!
Upvotes: 3
Reputation: 16468
Completely reset?
Delete the .git
directory locally.
Recreate the git repostory:
$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
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
Upvotes: 439
Reputation: 234354
First, follow the instructions in this question to squash everything to a single commit. Then make a forced push to the remote:
$ git push origin +master
And optionally delete all other branches both locally and remotely:
$ git push origin :<branch>
$ git branch -d <branch>
Upvotes: 7