KevinOrr
KevinOrr

Reputation: 1663

How can I remove everything from a remote Git repository?

How can I completely "start over" in-place?

How can I totally wipe out everything in a Git remote repository? I am the only client currently and before I can let it go public I have to wipe out all of the previous commits.

Not a duplicate because...

This question is about how to remove history, including the original base commit, without deleting the existing repository. My repository is on SourceForge, and the only way to do that is to destroy the whole project, which requires you to submit a Project Removal Request, which they don't always grant (especially in my case, where my project is younger than 90 days, so they won't grant it).

Upvotes: 2

Views: 7108

Answers (5)

Marc_Alx
Marc_Alx

Reputation: 1441

Here's a simple way to do that :

  1. Create an empty git repository.

    git init

  2. Make a dummy commit :

    touch README.md git add README.md git commit -m "first commit"

  3. Reference the repo you want to overwrite :

    git remote add origin REMOTE_URL

  4. Overwrite remote git

    git push --force origin

  5. Remove existing remote tag (one by one)

    git push --delete origin TAG_NAME

Upvotes: 0

mrutyunjay
mrutyunjay

Reputation: 8300

Use git push command to delete branch

$git push origin :remotebranch_name

this will delete remote branch completely

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

Push a (Mostly) Empty Branch

You have to have at least one commit on a branch in order to push it to a remote repository. If you have no heads at all, git won't have anything to send to origin. You can resolve this by making an empty branch with an empty commit. For example:

git symbolic-ref HEAD refs/heads/empty_branch
rm .git/index
git commit --allow-empty -m 'Initialize empty branch.'
git branch -M empty_branch master
git push --force origin

When you're done, both your current master and origin/master will contain exactly one file-free commit. The underlying objects in the repositories will eventually be reaped when git performs garbage collection.

Delete All Tags

If you want to delete all local and remote tags, you can push a set of empty references to the remote before deleting the tags locally. For example:

# Delete all tags present on the local host from the remote
# host in one push operation.
git for-each-ref --format=':%(refname)' --shell refs/tags |
    xargs git push origin

# Delete all local tags.
git tag -d $(git tag)

Upvotes: 3

cdhowie
cdhowie

Reputation: 169008

If the remote name is origin and you have force-push rights on the remote repository, this will delete every branch and every tag in the remote repository:

REMOTE=origin

for i in .git/refs/$REMOTE/origin/*
do
    git push $REMOTE :"`basename "$i"`"
done

for i in `git tag`
do
    git push $REMOTE :refs/tags/$i
done

This is a destructive operation, so make sure that you really want to do this first.

Upvotes: 1

Conner
Conner

Reputation: 31050

ssh to the server and do a rm -rf .git within the project directory. If you want to then put it under git again, run a git init.

Upvotes: 1

Related Questions