0

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.

jasonbarone
  • 172
  • 3
  • 17

2 Answers2

1

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

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

I think submodule is the right answer. By the follwing command:

git submodule add template_remote_repository templete

you will clone template worktree from remote. you can work under template folder as in other git worktree, except with a different remote.

gzh
  • 3,507
  • 2
  • 19
  • 23
  • Sorry I don't quite understand the answer, but it sounds like submodules are what you recommend as well. I'll look into that some more, thanks. – jasonbarone Mar 09 '16 at 04:48
  • @jasonbarone Please refer to [git submodule doc](https://git-scm.com/docs/git-submodule). The key is "_The other repository has its own history, which does not interfere with the history of the current repository. This can be used to have external dependencies such as third party libraries for example."_ – gzh Mar 09 '16 at 05:00