Set separate remote for pushing and pulling only subfolder

Set separate remote for pushing and pulling only subfolder

Let’s say I have two repos, repo A and repo B, which contains a folder with code similar to the code in repo A (doesn’t really matter how this actually has happened, but OK, let’s assume I’ve just copied contents from A).

Now I want following:

  • To work just as I got used to in repo A
  • To set and additional remote repo pointing to repo B, but pushing and pulling only this subfolder.
  • To push, when it needed to this repo B.

So, basically, I’m looking for the cheapest way to have something like reversed sparsed check out.

It seems exactly the kind of problem git-subtree1 tries to solve.

cd repoB
git subtree pull -P folder {repoA URL} {repoA branch}
... edit test commit... 
git subtree push -P folder {repoA URL} {repoA branch}

You can add a ref for and so publish anything in a repo. So, to maintain a separate branch that tracks the main branch’s subfolder, add this to your commit ritual:

# in your commit ritual (no need to be mainbranch-specific, 
# this will detect changes and add the tracking commits only as necessary),
if [ `git rev-parse mainbranch:path/to/subfolder` 
      != `git rev-parse subfolderbranch:path/to/subfolder` ]; then 
    git commit-tree -p subfolderbranch -p mainbranch 
              mainbranch:path/to/subfolder <<<"tracking mainbranch subfolder" 
    | xargs git update-ref -m"tracking mainbranch subfolder" refs/heads/subfolderbranch 
fi
.
.
.
.