Remove all git files from a directory?

I have a folder under version control. I want to make a copy of it to send around, but don’t want to include all the .git directories and the files underneath it.

Is there a way to remove all the git files instead of manually deleting all of them?

  • Does git rm remove all history of a file?
  • Tortoise Git - lost commits after a pull resulted in conflicts
  • How to install GitFlow for Windows
  • Abort a git cherry-pick?
  • Remove a folder from git tracking
  • Are any limitations exist as to using different versions of git software on the same physical repository?
  • How to force users to use email address in lowercase in GIT
  • Git blame: statistics
  • Git undo changes in some files
  • What is the difference between Forking and Cloning on GitHub?
  • Can I use a GIT repository with SVN clients?
  • git submodule from Hg repo?
  • 7 Solutions collect form web for “Remove all git files from a directory?”

    The .git folder is only stored in the root directory of the repo, not all the sub-directories like subversion. You should be able to just delete that one folder, unless you are using Submodules…then they will have one too.

    How to remove all .git directories under a folder in Linux.

    This find command will list all .git directories under the current folder:

    find . -type d -name ".git" \
    && find . -name ".gitignore" \
    && find . -name ".gitmodules"



    There should only be like 3 or 4 .git directories because git only has one .git folder for every project. You can do those by hand.

    If you feel like removing them all in one command and living dangerously:

    //Retrieve all the files named ".git" and pump them into 'rm -rf'
    //WARNING if you don't understand why/how this command works, DO NOT run it!
    ( find . -type d -name ".git" \
      && find . -name ".gitignore" \
      && find . -name ".gitmodules" ) | xargs rm -rf
    //WARNING, if you accidentally pipe a `.` or `/` to xargs rm -rf, 
    //then everything will be gone.  Which requires an OS reinstall.

    You can use git-archive, for example:

    git archive master | bzip2 > project.tar.bz2

    Where master is the desired branch.

    cd to the repo then

    find . -name ".git*" -exec rm -R {} \;

    do the job for me

    In case someone else stumbles onto this topic – here’s a more “one size fits all” solution.

    If you are using .git or .svn, you can use the “–exclude-vcs” option for tar. This will ignore many different files/folders required by different version control systems.

    If you want to read more about it, check out:

    Unlike other source control systems like SVN or CVS, git stores all of its metadata in a single directory, rather than in every subdirectory of the project. So just delete .git from the root (or use a script like git-export) and you should be fine.

    ls | xargs find 2>/dev/null | egrep /\.git$ | xargs rm -rf

    This command (and it is just one command) will recursively remove .git directories (and files) that are in a directory without deleting the top-level git repo, which is handy if you want to commit all of your files without managing any submodules.

    find 2>/dev/null | egrep /\.git$ | xargs rm -rf

    This command will do the same thing, but will also delete the .git folder from the top-level directory.

    Git Baby is a git and github fan, let's start git clone.