4

I want to pull from and push to only a subdirectory of a git repository. Here is an example of what I want to achieve:

Let's say, I have a repository, containing two folders A and B (they are top-level folders, if that matters). I want to work and push changes into B only, while others are working on A and maybe even on B as well. Because I want to commit my changes back, I can't put A in the .gitignore file, nor I can use git rm -rf --cached A, since A is needed by others, however, I know, I will never touch any of the files it contains, and I simply don't want to store the unnecessary files of it. I can't use submodules either, as I don't want to change the original repository, nor I want to maintain a secondary one.

So my questions are: is this even possible; and if so, how can achieve this?

Peter Varo
  • 11,726
  • 7
  • 55
  • 77
  • 1
    My question is: Why do you want to do this? It seems to me that submodules wouldn't be a terrible solution for your use case. – Tim Biegeleisen Jul 27 '15 at 16:03
  • @TimBiegeleisen as a matter of fact I personally don't want to do this, but my collegue is :P His only point is, that he has very limited spaces on his SSD, and the other top-level folder contains tons of *other* resources (models, textures, renders, etc.) which are very big, and he knows, he won't use them in any time in the future – Peter Varo Jul 27 '15 at 16:07
  • 1
    It'd be cheaper for your colleague to invest in a larger SSD than to work through this convoluted process, honestly. – Makoto Jul 27 '15 at 16:10
  • 2
    It sounds like your colleague wants [sparse checkout](http://stackoverflow.com/questions/2336580/sparse-checkout-in-git-1-7-0). – Raymond Chen Jul 27 '15 at 16:43

2 Answers2

3

You can't pull or push from a specific folder in your repo. You pull or push on a branch.

Have you considered making a branch and switching to it when working on B, this way, you won't pollute your team's work made on A ?

You could even rebase your branch if you want to retrieve the work made by your team on the main branch to your own branch.

topheman
  • 7,422
  • 4
  • 24
  • 33
2

One could add A into the .git/info/exclude file. That file works just like .gitignore, but won't leave the local machine and hence won't affect your coworkers.

Another way would be to split your repos and then use subtree instead of submodules to keep track of the changes in the subdirectory. Subtrees save one from some of the inconveniences caused by submodules, but it's still a little more work to keep it synced.

tarleb
  • 19,863
  • 4
  • 51
  • 80
  • I accepted @topheman's answer, because both of your answers are equally valuable, but he answered more quicly. But thanks for the effortm, I upvoted yours as well! Anyway, I'm already using subtree, but in our situation for this kind of task, it cannot be done => we don't need two repos, we need only one. When we use subtree, we use it with two repos, to actually maintain a subset of private parts which could be public (FOSS), as an inverse-mirroring tool. But that has a *different committing direction*. – Peter Varo Jul 27 '15 at 22:45
  • 1
    @PeterVaro You made the right choice :) My answer is more an extension to the above answer, it would have been strange to see it selected. Those real-life subtree examples are interesting, thanks! – tarleb Jul 28 '15 at 08:19