1

I want to reset my remote and local BitBucket git repository to the very beginning, removing all commits, files, history, etc.

How can I do this without deleting the repository itself?

bigdaveygeorge
  • 947
  • 2
  • 12
  • 32

2 Answers2

2

if you have a clone of the repository you can use terminal to enter the directory for the repository and do

git checkout --orphan latest_branch
git rm *
git rm -r *
git commit -am "resetting"
git branch -D master
git branch -m master
git push -f origin master

commit -am appends to the most recent commit
branch -D deletes the master branch and its commit history branch -m renames the new branch as master

This will delete the files locally as well

answer based on this previous answer to a similar question

Community
  • 1
  • 1
Matthew Ciaramitaro
  • 1,184
  • 1
  • 13
  • 27
0

For all branches/tags on the repo, you could just:

git push origin :some-branch-or-tag

Adjust the name of the remote and the branch or tag you want to remove from the repo.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • [remote rejected] master (deletion of the current branch prohibited) – bigdaveygeorge Apr 28 '17 at 16:24
  • Does the remote have a working tree? If that's the case then you are trying to remote the branch that is checked out on the remote. That would explain it. – eftshift0 Apr 28 '17 at 16:27
  • I have a master branch and 1 tag. I have cloned the repository to my local machine and made 6 commits, the files match on the local and remote repositories. I now just want to remove everything completely on local and remote and start again. – bigdaveygeorge Apr 28 '17 at 16:32
  • You could create the first commit on your local master and push --force it on the remote master. That would provide basically the same result (without having to resort to _deleting_ master from the remote, if it's not allowing you to). – eftshift0 Apr 28 '17 at 16:36