Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning only a subdirectory with git [duplicate]

I have a git repository that includes subdirectories. Example dirA/dirB. Is there any way to do a git clone on a Unix server to pull only files from a subdirectory (dirB)?

Is there some other git command other than clone that will do this?

How do I git a specific file?

like image 516
user1526912 Avatar asked Aug 06 '12 19:08

user1526912


People also ask

How do I clone a specific directory 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.

How do you download a subfolder from a github repo?

Step1: Input github url to the field at the top-right. Step2: Press enter or click download for download zip directly or click search for view the list of sub-folders and files. Step3: Click "Download Zip File" or "Get File" button to get files.

How do I clone only a specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.

Can I copy .git folder to another folder?

You are good to continue exactly where you left off: your older branch, unstaged changes, etc. This will just copy the source folder to destination/source . The correct command is rsync -azv --exclude '. git' source/ destination/ , which copies contents of source folder to destination folder.


1 Answers

Suppose your project is in a dir called project, and you want only those commits which touch project/dirB.

Then:

git clone project/ subproject/ cd subproject git filter-branch --prune-empty --subdirectory-filter dirB HEAD  

subproject will now contain the git history which touches dirB.

like image 51
unutbu Avatar answered Oct 04 '22 01:10

unutbu