Egor Tensin Egor Tensin - 1 month ago 4x
Git Question

Detaching a directory to be modified as a branch elsewere using Git

Let's say my project is laid out as follows:

├── Examples
│   ├── ExamplesA
│   ├── ExamplesB
│   └── ExamplesC
└── TheLibrary

So there is this awesome library I've developed and a few usage examples which I would like to be distributed along with the library.

The thing is, the library, and that library alone has to be checked into a TFS repository. At the same time, my boss asked me to keep a copy of the project as it is so that it can be used later on.

directory is a Git repository, of course. I was thinking about branching a single directory (namely,
), but how do I do that using Git? I've read about
, but I'm afraid I got lost somewhere in the jungle of endless
s and
es. Could somebody help me with that?

Ideally, I would love to have two branches:
with the whole project in it, and
with the contents of the
folder. Then I would create development branches and merge them to both of these branches above. Is that or something similar possible using Git?


OK, this is how I did it.

I splitted TheLibrary to the TheLibrary branch using

git subtree split -P TheLibrary -b TheLibrary

and then I made a separate branch for maintaing a copy of TheLibrary in TFS or wherever.

git branch TheLibrary-tfs TheLibrary

So then I simply cloned the repository into my TFS workspace and checked out the TheLibrary-tfs branch.

Whenever I make TFS-specific change, I simply commit and push it and it's saved in my local folder outside of the TFS repository.

Whenever I need to make a TFS-unrelated change, I do it in my local folder in the master branch and then push using

git subtree push -P TheLibrary . TheLibrary

so that the change is propagated to the TheLibrary branch. Then I merge the changes to the TheLibrary-tfs branch. Finally, I simply navigate to my TFS workspace and pull the changes from my local folder. Complicated, but works and appears to be just what I needed.