1

I have a project called channel, which has only one branch -- master. And I have another project called bigTest, which has four branches -- master, dev, stable, release.
Nowadays I want to add channel to the root directory of bigTest as a submodule of each branch of bigTest. I used git submodule add <url> for each branch of four. However I got modified: channel (untracked content) and modified .gitmodules appending branch = dev even though I used git config -f .gitmodules submodule.channel.branch dev on dev branch.
What should I do in order to add a submodule master to multiple branches of a project? Thank you!

Bryan YU
  • 77
  • 11

1 Answers1

1

The submodule.channel.branch should be set to master only, since the remote submodule repo (channel) has only one branch to follow anyway.

Once declared, you need add, commit and push from bigTest, since the .gitmodules has changed, and a gitlink (special entry in the index) representing channel root folder has been created.

However git status shows: Untracked files: (use "git add <file>..." to include in what will be committed) channel/ when I checkout master of bigTest.

The OP finds out why:

Yes, I compile and produce something in the submodule folder.
I can conclude that Git will show untracked content if something new created from submodules.

I recommend putting what is produce in the .gitignore of the submodule.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I can still not add ```channel``` to index in *dev*, *stable* or *release* branch of ```bigTest``` repo, showing ```modified: channel (untracked content)```. However ```git status``` shows: ```Untracked files: (use "git add ..." to include in what will be committed) channel/ ``` when I checkout master of ```bigTest```. That seems like I could add and commit ```channel``` submodule to master of ```bigTest```. – Bryan YU Jan 02 '19 at 06:01
  • @BryanYU what git status shows when executed from within the channel submodule folder? – VonC Jan 02 '19 at 06:02
  • You make sense! There are something left in submodule. After I commit them in submodule, ```modified: Channel_ANS_test (new commits)``` is shown in ```bigTest``` directory. Thank you! What should I do? I should push changes to remote in submodule and then commit and push changes to remote in parent repo. – Bryan YU Jan 02 '19 at 06:14
  • Strange, there should not be anything "changed" in the submodule folders. But if you do commit inside a submodule, you should push to the submodule remote repo, then go to the main parent repo, add, commit and push as well. – VonC Jan 02 '19 at 06:23
  • Yes, I compile and produce sth. in the submodule folder. I can conclude that the git will show ```untracked content``` if something new created from submodules. – Bryan YU Jan 02 '19 at 06:31
  • You could add what you are producing in the .gitignore of the submodule repo. – VonC Jan 02 '19 at 06:45
  • @BryanYU I have edited the answer to reflect those comments and their conclusion. – VonC Jan 02 '19 at 11:31
  • that's awesome! Thank you! – Bryan YU Jan 02 '19 at 12:07
  • @BryanYU No problem. Don't forget to read https://stackoverflow.com/help/accepted-answer. – VonC Jan 02 '19 at 17:26