Delete all git files from the directory?

I have a folder running version. I want to make a copy of it for sending, but I do not want to include all the .git directories and the files under it.

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

+51
git
Jan 27 '11 at 21:50
source share
7 answers

The .git folder is only saved in the root directory of the repo, and not in all subdirectories, such as subversion. You should be able to simply delete this one folder if you are not using Submodules ... then they will also have one.

+76
Jan 27 2018-11-11T00:
source share

How to delete all .git directories in a folder on Linux.

This find command will display all .git directories in the current folder:

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

Print

 ./.git ./.gitmodules ./foobar/.git ./footbar2/.git ./footbar2/.gitignore 

There should be only 3 or 4 .git directories, because git has only one .git folder for each project. You can do it manually.

If you feel that you delete them all in one team and live 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. 
+32
Nov 19 '13 at 20:29
source share

You can use git-archive , for example:

 git archive master | bzip2 > project.tar.bz2 

Where master is the branch to look for.

+13
Jan 27 2018-11-21T00:
source share

cd to repo then

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

do the work for me

+6
Aug 15 '15 at 6:20
source share

If someone else stumbles on this topic - there is more than "one size fits all."

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

If you want to know more about this, check out: http://www.gnu.org/software/tar/manual/html_section/exclude.html

+4
Jul 27 2018-12-12T00:
source share

Unlike other version control systems, such as SVN or CVS, git stores all its metadata in one directory, and not in every subdirectory of the project. So just remove .git from the root (or use the script as git-export ) and everything should be fine.

+1
Jan 27 2018-11-11T00:
source share

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

This command (and this is just one command) will recursively delete .git directories (and files) that are in the directory without deleting the top-level git repo, which is convenient if you want to transfer all your files without managing submodules.

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

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

0
May 11 '16 at 15:55
source share



All Articles