Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodules — exclude specific files/directories

I'm attempting to use Gits 'submodules' feature to include 3rd party code in a project. I only need a couple of files from the submodule and wish to exclude all the docs, etc that come with it.

How can I do this?

like image 321
hamishtaplin Avatar asked Apr 19 '12 12:04

hamishtaplin


People also ask

Is using git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

Should git submodules be in Gitignore?

No, you don't need to add your submodule to your . gitignore : what the parent will see from your submodule is a gitlink (a special entry, mode 160000 ). That means: any change directly made in a submodule needs to be followed by a commit in the parent directory.

How do I ignore changes in git submodules?

Another method is to use the swicth --ignore-submodules=dirty of git status (available from git version 1.7. 2) and create an alias to shorten the typing. Ignore changes to submodules when looking for changes. can be either "none", "untracked", "dirty" or "all", which is the default.

What does git pull -- recurse submodules do?

If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.


2 Answers

In my submodule I had an /examples folder I wanted deleted locally to prevent those files being seen by an autogenerated makefile; origin had to remain oblivious to the deletion.

In git CLI:

git update-index --assume-unchanged <path/to/file>

To track local changes once again:

git update-index --no-assume-unchanged <path/to/file>

Or in SourceTree, create a custom action as per Fabian Blechschmidt's answer.

NOTE This is not the same as "Stop tracking", where origin will indeed also stop tracking the file on commit - not what you want.

like image 137
Engineer Avatar answered Sep 20 '22 17:09

Engineer


A git submodule is a git repository embedded inside another git repository. Other than that there's nothing special about it -- a submodule behaves the same way as any other git repository. You get all the files and all the history associated with the repository when you clone it.

If you just want a couple of files and you're not interested in tracking the change history of the third-party project, maybe you should just copy the specific files into your project and call it done.

like image 45
larsks Avatar answered Sep 23 '22 17:09

larsks