How to completely clear git repository, without deleting it

nemo_87

How can I remove all files and folders that I'm storing on git repo, but keep the repository? Is there some command for restarting git repo? I've found many examples on this, but I've made even bigger mess. The repository is linked. So if someone is willing to explain it to me step by step I would be very thankful.

Chris Maes

if you only have a local git repository

if you want to erase your whole history and start over again:

cd <repo>
rm -rf .git
git init

and start committing again.

If you want to remove both files and history:

cd <repo>
rm -rf *
git init

and start adding files and committing...

if you are linked with a remote repository if you want to start over again, but don't really mind some old history remaining; there is a quick way:

git pull
git rm -r *
git commit
git push

now your repository is empty again, you'll only have some old history remaining. if you also want to clean up all your history; that takes a little more work (and note that this will cause trouble for anyone else linked to that same remote repository):

git checkout <first commit hash>
git rm -r *
touch README
git add README
git commit --amend
git push -f

note that I create a empty README file for the first commit, since a commit cannot be empty.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to remove a file from a git repository, without deleting it in cloned repositories

Removing Repository In Git Bash Without Deleting The Folder

Java - How to Clear a text file without deleting it?

Git: How to remove file from index without deleting files from any repository

Completely remove git repository

How can I clear remote repository in git?

Git change a project name without deleting and recreating project in repository

Remove a file from a Git repository without deleting it from the local filesystem

TYPO3 Repository completely deleting

How to completely replace remote repository git history with local copy?

How to delete a file from TFS repository without deleting local file

How to prevent users from deleting commit from remote git repository

Deleting local source of Git Repository

How to duplicate a git repository? (without forking)

How to clone git repository without network connection

How to clear bash history completely?

How to clear contents of table completely?

How to convert mercurial repository to git repository without losing branches?

How do I git rm a file without deleting it from disk?

How to delete a remote branch without deleting the local on git?

How to ignore the content of folder without deleting when deploying via git

How to delete parent directories without deleting its children directories in git?

Merge branch without deleting it in git

Deleting all Git cached submodules from repository

Deleting Git repository has deleted my project

How do I remove a repository from SourceTree without deleting the contents on disk?

On Linux, what is the correct way to completely empty a directory without deleting it?

Git deleting files without using git rm

How to completely clear pygame window with button