user105813
user105813

Reputation: 17477

How can I fully delete a Git repository created with init?

I created a Git repository with git init. I'd like to delete it entirely and initialise a new one.

Upvotes: 1692

Views: 1878666

Answers (17)

Vladyslav Ulianytskyi
Vladyslav Ulianytskyi

Reputation: 2541

In Android Studio, it could be done from menu Android StudioSettings:

Enter image description here

Upvotes: 0

MonirRouissi
MonirRouissi

Reputation: 631

You can use:

git remote remove origin

To remove a linked repository, then

git remote add origin <your repository>

to add a new one.

Upvotes: 5

leouonline
leouonline

Reputation: 388

After cloning the repository,

cd /repo folder/

To go to the file directory, then:

ls -a

To see all files hidden and unhidden,

.git .. .gitignore .etc

If you like, you can check the repository origin:

git remote -v

Now delete the .git folder, which contains everything about Git:

rm -rf .git

After deleting, you would discover that there isn't any Git linked check remote again:

git remote -v

Now you can initialise your repository with:

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/Leonuch/flex.git
git push -u origin main

Upvotes: 37

eckes
eckes

Reputation: 67037

Alternative to killing TortoiseGit:

  • Open the TortoiseGit-Settings (right click to any folder, TortoiseGit → Settings)
  • Go to the Icon Overlays option.
  • Change the Status Cache from Default to None
  • Now you can delete the directory (either with Windows Explorer or rmdir /S /Q)
  • Set the Status Cache back from None to Default, and you should be fine again...

Upvotes: 16

Kristof Provost
Kristof Provost

Reputation: 26322

Git keeps all of its files in the .git directory. Just remove that one and initialise again.

If you can't find it, it's because it is hidden.

  • In Windows 7, you need to go to your folder, click on Organize on the top left, then click on Folder and search options, then click on the View tab and click on the Show hidden files, folders and drives radio button.

  • On a Mac OS X:

    • Open a Terminal instance (via Spotlight: press CMD + SPACE, type terminal and press Enter) and run:

        defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
      

    Note: The keyboard shortcut to show hidden files in Finder is CMD + SHIFT + ., so it isn't necessary any longer to modify the Finder configuration this way

    • You could also type cd (the space is important), drag and drop your Git repository folder from Finder to the terminal window, press return, type rm -fr .git, and then return again.
  • On Ubuntu (Linux), use shortcut Ctrl + H.

Upvotes: 2089

Gayathri Raghuram
Gayathri Raghuram

Reputation: 21

rm -rf .git worked for me I did a ls -a to see all hidden files/folders first.

Upvotes: 0

Ahmad Awais
Ahmad Awais

Reputation: 37060

You can create an alias for it. I am using ZSH shell with Oh-my-Zsh and here is an handy alias:

# delete and re-init git
# usage: just type 'gdelinit' in a local repository
alias gdelinit="trash .git && git init"

I am using Trash to trash the .git folder since using rm is really dangerous:

trash .git

Then I am re-initializing the git repo:

git init

Upvotes: 3

Scorpius
Scorpius

Reputation: 1009

Where $GIT_DIR is the path to the folder to be searched (the git repo path), execute the following in terminal.

find $GIT_DIR -name *.git* -ok rm -Rf {} \;

This will recursively search for any directories or files containing ".git" in the file/directory name within the specified Git directory. This will include .git/ and .gitignore files and any other .git-like assets. The command is interactive and will ask before removing. To proceed with the deletion, simply enter y, then Enter.

Upvotes: 11

Vin Norman
Vin Norman

Reputation: 3292

For Windows PowerShell users:

rm -Recurse -Force .git*

This will remove the .git folder, and all the .gitignore, .gitattributes files.

Upvotes: 4

Deepak Keynes
Deepak Keynes

Reputation: 2329

No worries, Agreed with the above answers:

But for Private project, please follow the steps for Gitlab:

  1. Login to your account
  2. Click on Settings -> General
  3. Select your Repository (that you wants to delete)
  4. Click on 'Advanced' on the bottom-most
  5. Click on 'Remove Project'
  6. You will be asked to type your project name

    This action can lead to data loss. To prevent accidental actions we ask you to confirm your intention. Please type 'sample_project' to proceed or close this modal to cancel.

  7. Now your project is deleted successfully.

Upvotes: 2

Shema05
Shema05

Reputation: 1

true,like mine was stored in USERS,so had to open USERS go to View on you upper left find Options,open it and edit folders'view options in view still to display hidden files/folders,all your folders will be displayed and you can deleted the repo manually,remember to hide the files/folders once done with the delete.

Upvotes: -2

SridharKritha
SridharKritha

Reputation: 9611

Windows cmd prompt: (You could try the below command directly in windows cmd if you are not comfortable with grep, rm -rf, find, xargs etc., commands in git bash )

Delete .git recursively inside the project folder by the following command in cmd:

FOR /F "tokens=*" %G IN ('DIR /B /AD /S .git') DO RMDIR /S /Q "%G"

Upvotes: 0

sahil khurana
sahil khurana

Reputation: 49

In windows:

  1. Press Start Button
  2. Search Resource Monitor
  3. Under CPU Tab -> type .git -> right click rundll32 and end process

Now you can delete .git folder

Upvotes: 0

squal
squal

Reputation: 185

To fully delete the .git repository in your computer (in Windows 8 and above):

  1. The .git repository is normally hidden in windows
  2. So you need to mark the "hidden items" to show the hidden folders
  3. At the top site of you directory you find "view" option
  4. Inside "view" option you find "hidden items" and mark it
  5. Then you see the .git repository then you can delete it

Upvotes: 5

P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

I tried:

rm -rf .git and also

Git keeps all of its files in the .git directory. Just remove that one and init again.

Neither worked for me. Here's what did:

  • Delete all files except for .git
  • git add . -A
  • git commit -m "deleted entire project"
  • git push

Then create / restore the project from backup:

  • Create new project files (or copy paste a backup)
  • git add . -A
  • git commit -m "recreated project"
  • git push

Upvotes: 4

ejazz
ejazz

Reputation: 2508

If you want to delete all .git folders in a project use the following command:

find . -type f | grep -i "\.git" | xargs rm

This will also delete all the .git folders and .gitignore files from all subfolders

Upvotes: 73

CB Bailey
CB Bailey

Reputation: 791401

If you really want to remove all of the repository, leaving only the working directory then it should be as simple as this.

rm -rf .git

The usual provisos about rm -rf apply. Make sure you have an up to date backup and are absolutely sure that you're in the right place before running the command. etc., etc.

Upvotes: 1061

Related Questions