Clear git repository on Bitbucket?

GitBitbucket

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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://[email protected]/banana/test.git

The command should look like this:

git push --force -u https://minim[email protected]/banana/test.git master

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMTCosterView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitprotaruView Answer on Stackoverflow