1

Suppose there is an online repository with url https://website.domain/repo.git and its structure is something like this.

repo/
|
|--a/
|  |
|  |--aa/
|  |
|  |--ab/
|
|--b/

I only work with the sub-directory aa and have nothing to do with the rest of the repository. So I only need to track aa (The whole repository is pretty big). Now, I don't have any authority over this online repository, otherwise I would've simply turned aa into a submodule.

In short, how do I set repo/a/aa as origin instead of the whole repo so that I can pull any changes to repo/a/aa?

nomad
  • 471
  • 6
  • 12
  • 1
    Nop, no way. In such situation I'd clone the entire `repo.git`, extract the subdirectory into a separate repo using `git subtree` and import the new repo into you project using `git submodule` or `git subtree`. Later when you get know the upstream repo is updated you update your local clone, update the extracted subdirectory using the same `git subtree` and update your project. That's the simplest way I could imagine. – phd Apr 24 '20 at 15:01
  • @phd, that's what I am doing at the moment. You probably already know this, but git, like any agile software being developed everyday doesn't always have documentation which is as up to date as the software itself. For example, some git sub-command which was implemented recently may not have been documented yet. This question is directed towards someone who is more acquainted than I am with the inner development of git (a contributor/maintainer for example), so that I can find out about a tool like that. – nomad Apr 24 '20 at 16:06
  • Also like I said, the whole repository is pretty big (a couple of gigs as opposed to a few MB which I am working with) and I don't have a good bandwidth at my region. Otherwise, I wouldn't have bothered with looking for something like this. – nomad Apr 24 '20 at 16:09
  • You only need good bandwidth for the 1st clone. Updates are usually small and cheap. – phd Apr 24 '20 at 17:37
  • @phd, my work environment is in a live image, that is not an option. – nomad Apr 24 '20 at 17:44

1 Answers1

1

The short answer is that you can't—not yet, anyway.

That's not 100% right: there is a bunch of experimental stuff using promisor packs and filter expressions. The documentation that does exist for this is here; there is more information about all of this in What is the git clone --filter option's syntax?

None of this stuff is ready for anyone to use. You should feel free to experiment with it, but if you get something working in Git 2.2x, it might stop working in the next version of Git. This isn't like git switch and git restore, which are still marked experimental, but are pretty well defined and not likely to break tomorrow. This is stuff with known limitations, bugs, incompatibilities between specific Git revisions, and code that's just not really there yet.

(Side note: beware of the verb track, which already has about 3 or 4 meanings in Git, none of them compatible with each other, nor with what I think you mean by your word track here.)

torek
  • 448,244
  • 59
  • 642
  • 775