Home > front end >  .gitginore for ignoring a submodule doesn't work as intended
.gitginore for ignoring a submodule doesn't work as intended

Time:10-08

I have a folder called app in my original repository and inside it a .gitignore which simply ignores everything inside the folder (except itself). I would like to add a submodule inside app folder and I would like this submodule to be visually ignored by the original repository where I can't see the submodule directory (in GitHub where the original repo was published) but can update it and get updates when there are (since the folder will be locally there but won't be seen by the original repo).

However, whenever I try to add the submodule using git add submodule command, I get new changes in my original repo that I just added something. I don't want this.

Any idea to prevent this?

CodePudding user response:

If you do not want to link the parent project to the submodule, then consider cloning the child project as a normal repo inside the parent project. That way, you can tell git to ignore the directory that is holding the child project and you should be fine. Being at the root of the parent project:

git clone url-to-child-repo child-project # use the directory of your choice, of course

Now that we have the project there, let's ask git to ignore it. We can either do it with .gitignore:

echo child-project >> .gitignore

Which will modify .gitignore and you might be tracking it or not.... or you can do it just for you:

echo child-project >> .git/info/exclude

And then you have the child project right there and the parent project does not know about it.

  • Related