Install a separate remote control for pressing and pulling out only the subfolder

Let's say I have two repositories, repo A and repo B , which contains a folder with code similar to the code in repo A (it doesn't really matter how it actually happened, but well, let's just copy the contents from A).

Now I want:

  • To work the same way I'm used to repo A
  • For installation and an additional remote repo pointing to repo B, but pressing and pulling only this subfolder.
  • To click when necessary for this repo B.

So basically, I'm looking for the cheapest way to have something like a deferred check.

+4
source share
4 answers

One approach is to set up a third repository containing common code for both projects, and then use this repository as a submodule in both repositories A and B.

However, if I understand your question correctly, the entire repository A is the "common" code. In this case, there is no need for a third repository, and you can simply add A as a submodule inside B.

+2
source

It seems that exactly the git-subtree 1 problem is trying 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} 
+2
source

You can add a link and, thereby, publish something in the repo. Thus, to save a separate branch that tracks the main 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 
+2
source

Clone repoA to create a new repo. Then set the bit unchanged for everything except the subfolder:

 git update-index --assume-unchanged * git update-index --no-assume-unchanged <subdirectory> 

Note: the file / directory argument must NOT begin with . or /

After that, you can delete everything except the subfolder. Due to the supposed-unchanged bit, git won't notice this. Now work as if it would be a regular repository. You can copy the modified files from the old repoB to this one.

Please note that clicking and pulling can create files that are not already in a subfolder. To avoid this, you can create a binding to delete everything except the subdirectory.

+1
source

Source: https://habr.com/ru/post/1500111/


All Articles