{"thread":{"id":"62912","subject":"Managing one github repo with Gitignore and Submodules for two different remotes","startedAt":"2025-02-06T14:10:55Z","lastAt":"2025-02-06T22:23:41Z","messageCount":2,"participants":["USA Linux UAE","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"512000","messageId":"CAOXJ2J-StZYg4E9eGug=wHNjBu3aPdoy0x17aS9jLn14SyfJkA@mail.gmail.com","threadId":"62912","inReplyTo":null,"subject":"Managing one github repo with Gitignore and Submodules for two different remotes","fromName":"USA Linux UAE","fromEmail":"usasoftwareengineer@gmail.com","sentAt":"2025-02-06T14:10:44Z","receivedAt":"2025-02-06T14:10:55Z","isPatch":false,"sender":{"key":"usasoftwareengineer@gmail.com","avatar":null},"body":"Hi everyone,\n\nI'm hoping to get some advice on managing a GitHub repository with a\nslightly complex setup. We have a main repo that utilizes both a\n.gitignore file and submodules. Our goal is to push this repo to two\ndifferent remote repositories (let's call them remote_A and remote_B),\nbut with a key difference:\n\nremote_A should respect the .gitignore file as usual, excluding the\nfiles and directories specified within it.\nremote_B should effectively ignore the .gitignore file, and include\nall files and directories, even those listed in .gitignore.\nEssentially, we want the opposite behavior of .gitignore for remote_B.\n\nAdditionally, we need to ensure the submodules are handled correctly\nfor both remotes. Ideally, the submodule pointers should remain\nconsistent, regardless of which remote we're pushing to.\n\n\nCould anyone offer advice on the best approach for this scenario? Are\nthere any recommended workflows or tools specifically designed for\nthis type of setup? Any insights regarding submodule management in\nthis context would be greatly appreciated.\n\nThanks in advance for your help!\n\nAmjad\n"},{"id":"512019","messageId":"Z6U2a0l0kX0MmNFN@tapette.crustytoothpaste.net","threadId":"62912","inReplyTo":"CAOXJ2J-StZYg4E9eGug=wHNjBu3aPdoy0x17aS9jLn14SyfJkA@mail.gmail.com","subject":"Re: Managing one github repo with Gitignore and Submodules for two different remotes","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-02-06T22:23:39Z","receivedAt":"2025-02-06T22:23:41Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-02-06 at 14:10:44, USA Linux UAE wrote:\n> Hi everyone,\n> \n> I'm hoping to get some advice on managing a GitHub repository with a\n> slightly complex setup. We have a main repo that utilizes both a\n> .gitignore file and submodules. Our goal is to push this repo to two\n> different remote repositories (let's call them remote_A and remote_B),\n> but with a key difference:\n> \n> remote_A should respect the .gitignore file as usual, excluding the\n> files and directories specified within it.\n> remote_B should effectively ignore the .gitignore file, and include\n> all files and directories, even those listed in .gitignore.\n> Essentially, we want the opposite behavior of .gitignore for remote_B.\n\nUnfortunately, there is no easy way to do what you want because you\nessentially have two separate, independent, and diverging histories.\nGit doesn't offer functionality to push only part of the history, and\n`.gitignore` is honoured when files are added, not when pushing.  Once\nfiles have been added, `.gitignore` has no effect.\n\n> Additionally, we need to ensure the submodules are handled correctly\n> for both remotes. Ideally, the submodule pointers should remain\n> consistent, regardless of which remote we're pushing to.\n> \n> \n> Could anyone offer advice on the best approach for this scenario? Are\n> there any recommended workflows or tools specifically designed for\n> this type of setup? Any insights regarding submodule management in\n> this context would be greatly appreciated.\n\nThe best way to do what you want is to put the extra files from the\nsecond case in a separate submodule, which can be pushed to server B but\nnot server A.  You may want to add a script to handle the case where\nthey do or don't exist and place them in the proper place via copy or\nsymlink if they're present.  You'll want to ignore them in the main\nrepo, though, since you don't want them to be checked in accidentally.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}