简体   繁体   中英

How do I link a shared common git repo as a subdir in other project repos

I have been unable to find the answer to this question after a couple of days of searching and finding hints suggesting 'git remote' and 'git submodule' but lacking sufficient clarity.

I wrote a CLI python script Banner.py containing a useful importable function. (see ' https://github.com/jlettvin/Banner '). I use it in Makefiles, bash scripts, and as a function in other python scripts.

Now suppose I have projects A and B, both of which could use that script and function. I want to make a 'util' directory in both A and B containing Banner.py. Then I want to call '$(HOME)/util/Banner.py' in Makefiles and import Banner into python scripts in those projects too.

While working on project AI discover a tweak must be made to Banner.py. I want to modify Banner.py in project A, commit and push it in project A, and then use pull in project B to get the updated version and also pull the Banner repo independently elsewhere.

  1. What git commands do I use to link the Banner project to projects A and B?
  2. Will 'git status' in project B alert me to the Banner repo change?
  3. Can I be notified which projects to pull when I push Banner from project A?

The first question is the one that matters the most to me. If I can modify the Banner repo and then silently pull it when I pull repos A and B, that might suffice, but I'd like better.

Use git submodules, read more here http://git-scm.com/book/en/v2/Git-Tools-Submodules . You will have a submodule for your Banner.py and it will be added to both your A and B projects. Each can recursively update their respective submodules to pull in new changes, but it won't happen automatically (since you really should know when code revisions get changes, so you usually have to update it and commit the fact that you updated it in your A/B repos).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM