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

ID : 20113

viewed : 28

Tags : gitversion-controlgit

Top 5 Answer for version control - Git: How to reset a remote Git repository to remove all commits?

vote vote

95

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 
vote vote

80

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> 
vote vote

80

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!

vote vote

70

vote vote

57

if you use Azure Devops:

  1. Under your project repo, select Branches.

  2. On the Branches page, select More options next to the new default branch you want, and choose Set as default branch.

enter image description here

  1. After you set the new default branch, you can delete the previous default if you want.

Top 3 video Explaining version control - Git: How to reset a remote Git repository to remove all commits?

Related QUESTION?