Search code examples
gitgithubrepositorygit-submodulesgit-subtree

Is it possible to track a folder in my repo, and also track the same folder as its own repo?


I'm working with my top-level project repo, which contains one subfolder that's a combination of project code as well as some build code. I want to track this subfolder in my top-level repo, but I also need to track this subfolder as part of its own repo because we need to use Git to deploy our subfolder directly to our web platform.

Here's how the top-level repo looks:

|--js
|----lib
|----src
|--sass
|--template
|----assets
|----collections
|----scripts
|----styles
|----.gitignore
|----site.region
|----template.conf
|--.eslint
|--.gitignore
|--package.json
|--README.md
|--webpack.config.js

I'd like to track everything you see above in my top-level repo.

However, template needs to have Git remotes for our web platform, so this folder must also be a git repo.

How do I best set this up? I've read into Submodules and I'm not sure that will help me in this scenario. My web platform is setup to accept ONLY the template folder and nothing more.


Solution

  • As suggested in your question add the submodule folder.

    git submodule add <url>
    

    Now when you clone the project you simply need to init and update the submodule

    git submodule init
    git submodule update
    

    Git 1.8.2 features a new option --remote

     git submodule update --remote --merge
    

    --remote

    This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.

    This is equivalent to running git pull in each submodule.


    Here is what submodule looks like - repository inside repository:

    enter image description here