Pulling only one directory from git repository

I have a git repository from which I want to make. I am doing regular git pull without any problems. The problem is that I want the repo to have only one specific directory. I thought I could use a .gitignore file with this rule:

 #Ignore all files / #Except the one I want !/temp 

The problem is that this does not work. Is this the right way to do this, or is there a better way?

+7
source share
1 answer

git pull retrieves and merges the remote branch.

.gitignore only works locally and will hide the corresponding entries from being displayed on git status and added to the index using git add . This is not what you want.

What you want to do is fetch remote branch, and from this, extract the required file / file.

 $ git fetch <remote> <branch> $ git checkout <remote>/<branch> -- relative/path/to/file/or/dir 

the / dir file should now be in your branch and added to the index.

+25
source

All Articles