Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone, ignoring a directory

Tags:

git

I'm trying to test something on a wordpress install. In doing so, I'd like to quickly replicate the repo. However, the upload directory (wp-content/uploads) is massive, so I'd like to ignore it.

Note: I don't want to .gitignore this directory all the time, just for this scenario.

Basically, I'd like a command like this pseudo code: git clone --ignore wp-content/uploads.

Is the best way to add that directory to .gitignore, clone, and then revert .gitignore? Or is there a better method?

like image 203
hookedonwinter Avatar asked Jan 14 '13 20:01

hookedonwinter


People also ask

Can you git ignore a folder?

The . gitignore file allows you to exclude files from being checked into the repository. The file contains globbing patterns that describe which files and directories should be ignored.

How do you add a folder to git ignore?

If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.

How do I clone a specific folder from a git repository?

If you want to clone the git repository into the current directory, you can do like: $ git clone <repository> . Here, the dot (.) represents the current directory.


2 Answers

A bit late to the party, but: Don't you want a sparse checkout?

mkdir <repo> && cd <repo> git init git remote add –f <name> <url> 

Enable sparse-checkout:

git config core.sparsecheckout true 

Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout:

echo some/dir/ >> .git/info/sparse-checkout echo another/sub/tree >> .git/info/sparse-checkout 

Checkout from the remote:

git pull <remote> <branch> 

See http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/ for more info.

like image 168
Rogier van het Schip Avatar answered Oct 14 '22 13:10

Rogier van het Schip


git clone will always clone the complete repository*, including all previous commits ever added to the repository. So even if you remove the files temporarily, and clone it then, you will still receive the older versions which do contain those files.

Also, just editing the .gitignore will not remove tracked files from the repository even if they would normally be ignored.

So no, it is not really possible to skip a certain folder during cloning.

*It is possible to limit the amount of commits retrieved during a clone, but this will not make the repository very usable.

like image 24
poke Avatar answered Oct 14 '22 14:10

poke