81

I'm just getting started with git, and started messing about with Bitbucket. However, I now want to use the repository I created, but without its initial history.

Is there any way I can clear out or purge my repository so that I can start from scratch?

I'm not too bothered about any of the content, so can I just delete the repository, then create a new one with the same name?

alex
  • 479,566
  • 201
  • 878
  • 984
MTCoster
  • 5,868
  • 3
  • 28
  • 49

2 Answers2

157

No need to delete it.

From your new local repo create directory or remote simple the .git, if you want upload (without history) an existing repo:

 rm -rf .git

Recreate the repos from the current content only

 git init
 git add .
 git commit -m "Initial commit"

Then simply push to the github remote repos ensuring you overwrite history:

 git push --force -u origin master

That will replace the history of your BitBucket master branch by the new one you have done locally.

Now, if you had pushed other branches before, you might want to delete them.

git push origin :oldBranch
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Great, thanks! Is there any way to remove the stripping from the recent activity log? – MTCoster Dec 02 '12 at 12:57
  • @MatthewCoster good question. I am not aware of a way to modify that list of activities recorded on the BitBucket side. (a bit like silently deleting a BitBucket repo: https://bitbucket.org/site/master/issue/4271/make-it-possible-to-silently-delete-a). That might be an issue or request for enhancement to add to https://bitbucket.org/site/master/issues?status=new&status=open – VonC Dec 02 '12 at 13:06
  • 2
    this is not an answer. He asked how to clean (empty) repo, not how to replace content of remote repo with local changes – qkx Mar 07 '19 at 16:13
  • 2
    @qkx I accepted this answer 7 years ago because it did in fact answer my question. My stated intent was to start a new project in the repo, not leave an empty one. This achieves the former without the latter being necessary - an elegant avoidance of the XY problem. – MTCoster Mar 08 '19 at 13:45
  • I updated the answer to show little bit more the possibilites, since I wasn't found all I want to know here. – Christian Müller Jun 26 '20 at 15:26
  • 1
    @ChristianMüller Yes, thank you for your contribution. Much appreciated. I was the one who approved that edit. – VonC Jun 26 '20 at 15:36
3

Indeed it works, but for the push command you will need to provide again the full path to the repo, since the local repo was reinitialized. So origin will need to be replaced with something like this: https://minime@bitbucket.org/banana/test.git

The command should look like this:

git push --force -u https://minime@bitbucket.org/banana/test.git master
Obsidian
  • 3,719
  • 8
  • 17
  • 30
protaru
  • 29
  • 4