You have a couple options, though each is going to introduce some overhead.
Git submodules
No one really likes submodules, but they're in Git for this purpose. Split example/B
into its own repository, remove the directory from example
, and then re-include the example/B
repository as a submodule of example
.
Once that's done, you'll be able to commit to the example/B
repo and push to server B
without the rest of the project. example
won't contain the changes until you update the submodule.
Fake submodules
People call it fake submodules, but really it's just nesting one repository inside another. Get into example/B
and run git init
to create a brand new repo. Git looks for .git/
in your current directory first, then walks up the parents, so when you're in example/B
, Git will operate on the new repository, and when you're in example
, Git will operate on the original one. Like before, now you can commit to example/B
and push it to server B
without the rest of the project.
The difference between this strategy and real submodules is when you navigate back up to example
, you have to commit the change again to the main repository.
Other ideas
If example/B
is independent enough to be interesting to server B
without the rest of the main project, maybe it shouldn't be part of the main project at all. Maybe it makes sense to split completely into its own project and then include it as a totally external dependency of the current one.