Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add specific files recursively in git? [duplicate]

To commit something on git using git bash on windows I need to do, e.g.:

1.git add *
2.git commit -m "Commit test"
3.git push origin master

In such way I commit all changes. I would like to add only specific files (*.h and *.cpp). The solution is to use:

ad. 1.:
git add *.h
git add *.cpp

But in such way I add only *.h and *.cpp in current folder. The question is how to add files *.h and *.cpp in current folder and subfolders in one command? Something like:

1.git add *.h and *.cpp and_in_subfolders
and then:
2.git commit -m "Commit test"
3.git push origin master

Thanks.

like image 884
user2856064 Avatar asked Sep 11 '25 10:09

user2856064


1 Answers

If you use

git add *.h

The shell will expand the wildcard using files in the current folder.

Git can expand wildcards on its own as well, moreover it does that in the way you want (recursively) so you just need to prevent the shell from expanding the wildcard:

git add '*.h'
like image 141
StenSoft Avatar answered Sep 12 '25 23:09

StenSoft