4

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.

poke
  • 369,085
  • 72
  • 557
  • 602
user2856064
  • 541
  • 1
  • 8
  • 25

2 Answers2

10

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'
StenSoft
  • 9,369
  • 25
  • 30
1

It is best to used a bash command instead of relying on the '*' interpreted by the shell (and not recursively).

find . -type f -name '*.h' -exec git add {} \; 

Another approach is with xargs

find . -type f -name '*.h' -print | xargs git add 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250