How to fully delete a git repository created with init?

前端 未结 13 1802
再見小時候
再見小時候 2020-11-22 16:42

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

相关标签:
13条回答
  • 2020-11-22 17:11

    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.

    0 讨论(0)
  • 2020-11-22 17:14

    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 back the Status Cache from None to Default and you should be fine again...
    0 讨论(0)
  • 2020-11-22 17:16

    Git keeps all of its files in the .git directory. Just remove that one and init 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:

      • Open a Terminal (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 is no longer necessary to modify the finder config this way

      • You could also type cd (the space is important), drag and drop your git repo folder from Finder to the terminal window, press return, then type rm -fr .git, then return again.

    • On Ubuntu, use shortcut Ctrl + H.

    0 讨论(0)
  • 2020-11-22 17:17

    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.

    0 讨论(0)
  • 2020-11-22 17:19

    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

    0 讨论(0)
  • 2020-11-22 17:20

    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
    
    0 讨论(0)
提交回复
热议问题