3

Is there a way to only git pull the contents of a repository without pulling the home folder? For example I have a bunch of files in a repository called "sample" but I only want to pull the contents of "sample" into my local repository called "local." I do not want to pull "sample" such that I get: local -> sample -> [contents]. Is there a way to only pull the contents?

I'm asking because I am operating on a shared web server that requires that I place my content under a specific folder (and named certain file names within the folder).

Thanks.

EDIT: I wasn't being quite clear before. I'm working on a local machine such that I am only allowed to change the contents of my folder and not the contents of the folder that contains my folder.

user1246462
  • 1,228
  • 3
  • 11
  • 20
  • possible duplicate of [How to pull specific directory with git](http://stackoverflow.com/questions/2425059/how-to-pull-specific-directory-with-git) – Gabriele Petronella Apr 05 '13 at 01:11

1 Answers1

2

Option 1::

git clone <repo_path> <folder name>

So in your case, it would be git clone sample.git local

Option 2::

The folder-name where local repo is present does not have to be the same as that of the remote.

do a git clone ...

git clone repo_pathOrURL

then rename the folder

So for instance you have sample.git as your remote repository, do

git clone sample.git

This will clone the repository in a folder called sample on your local machine. Then just rename this folder to your liking, in your case local, and continue with the regular git pull and push.

vijay
  • 2,646
  • 2
  • 23
  • 37
  • 1
    I'm not allowed access to change the contents of the folder on the path before mine. Yes, it's a difficult system to work under. – user1246462 Apr 05 '13 at 01:09
  • ahhh yes, the first is great. Trying it out now. Thanks! – user1246462 Apr 05 '13 at 01:12
  • I'm now running into the problem of not being able to clone the repository because it is not an empty repository. Any suggestions on how to fix this so that I don't have to delete all the files in my directory? – user1246462 Apr 05 '13 at 01:25
  • what do you mean by "not an empty repository" ? maybe you can share the error message that you are getting? – vijay Apr 05 '13 at 01:32
  • fatal: destination path 'sample' already exists and is not an empty directory. – user1246462 Apr 05 '13 at 01:35
  • if you care about the changes that you made, then first push the change to the remote, then delete the contents of the folder, and then clone into the folder again. if the folder is empty you should have no issues in doing the git clone. – vijay Apr 05 '13 at 01:39
  • This worked for me. Also, if you cd to the dir you want to pull to, you can `git clone .` – wetjosh Apr 11 '16 at 19:16