top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is there a way to clone only specific folders from a remote GIT repository ?

+3 votes
1,111 views

When we clone a remote GIT repository, all folders/files will be cloned. This will consume lot of disk space in our local machine.
Is there a way to clone only few folders & exclude others?

This is possible in clearcase snapshot view by changing load rules.

posted Feb 10, 2016 by Shivananda Gavalkar S

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
This is called a sparse checkout,  please check the following https://git-scm.com/docs/git-read-tree (last section)

1 Answer

+2 votes

Suppose you already have a repository, simply enable and configure sparse-checkout and do git read-tree.

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

Update your working tree:

git read-tree -mu HEAD

I hope I understood your problem correctly.

answer Feb 10, 2016 by anonymous
Similar Questions
+1 vote

There's a challenge that i'm currently facing after migration from WINCVS to GIT. The problem here is I need to pull/fetch a specific branch (and NOT clone the entire repository) from the repository to a particular location on the AIX server.

Earlier while using WINCVS this functionality was achievable using JCVSExport package as we could just checkout a particular branch and fetch the package on to the server location.
WINCVS Command : java JCVSExport -h cvs.xyz.com -u abcde -p xxxxxx -d /abcd/cvs/testing -c "$REPOSITORY" -m "$PACKAGE"

I am not able to achieve the same functionality using GIT. I DO NOT want to clone the entire repository on the AIX server instead I just want to fetch/pull a specific branch contents on the server. Can someone please help me out with the solution or any possible way with which I can achieve the same functionality.

+1 vote

How to configure a read-only copy of a remote Git repository on a local server in bare mode and automatically synchronize its contents.

I need to configure a mirror of the repository hosted at another location and the mirrored repository should automatically perform syncing of code at regular intervals.

0 votes

Is there any reason why 'git clone -b' only takes a branch (from refs/heads/) or a tag (from refs/tags/) ?

Background: At $dayjob we're using some kind of 'hidden' refs (in refs/releases/) to communicate between the 'branch integrator' (who creates the ref in refs/releases/) and the 'build master' who wants to build that ref.

It would be a little easier if the build master could simply say

git clone -b refs/releases/the-release-for-today URL
instead of: git clone... ; cd ... ; git fetch... ; git checkout....

Any answer or even a better idea to solve that is appreciated.

+1 vote

I am new to git. I have followed the instructions given at https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb and successfully installed gitweb. I am using git 2.2.2 and it is installed on Linux.

After the successful installation and configuration of gitweb, I could able to see my git repositories when I hit my url like... http://ipaddress ( and I could see all the git projects/repositories listed here)

Now, I would like to my team members to clone these repositories to their local machines (all windows) using either git bash or tortoise git. However, we are unable to find or get the git clone url for these projects which are on gitweb.

How can I achieve this. Please help.

For your information, there are 5 git repositories on my Linux box (in which same git and gitweb are installed) and they are present under /root/git_projects/

0 votes

As far as I can tell, there is no way I can create remote git repository from command line (git.exe in windows). if I am not mistaken shall you tell me why such limitation exist given that git is an old and mature project.

...