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?

  • Error when starting gitk
  • Git | Branching model for a large project
  • Git workflow for compile machine
  • Is there a way to modify the width of elements in the IntelliJ statusbar (esp, the current git branch)
  • iPhone : How do I add existing project in “git local repository”?
  • Refresh code without overwriting my changes
  • Generating git diff
  • Apply patches created with git log -p
  • Why does the file glob **/*.cs in git grep not show me all *.cs hits?
  • Moving all commits beyond initial commit off master
  • Mercurial to Git
  • Setup Git-server on windows computer
  • 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.