-2

I want to setup git to stage only certain files of type. With

git add * 

in basic dir, i must stage only the files of type cpp,h,txt,html. How i must do this?

phd
  • 82,685
  • 13
  • 120
  • 165
jim kaip
  • 1
  • 5

1 Answers1

0

Just use wildcard * like this:

git add *.cpp
git add *.h
git add *.txt
git add *.html

* matches any number of characters, so pattern *.txt will match ale files with names ending with .txt.

To make this even easier, you can set your own git alias to add only certain files:

git config --local alias.addHtmlFiles 'add *.html'
git config --local alias.addTextFiles 'add *.txt'
git config --local alias.addCppFiles 'add *.cpp'
git config --local alias.addHeaderFiles 'add *.h'

Now you just use

git addHtmlFiles 
git addTextFiles 
git addCppFiles 
git addHeaderFiles 

to add wanted files.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • Thank you, but i am looking for a global setting. You know, sometime maybe use git add * by mistake, and then all, maybe thousandths of files add to stage. I am looking a way to set git to do it globally. Can i use for example git config --local alias.addHeaderFiles 'add *.h|*.cpp|*.html|*.txt' ? – jim kaip Dec 13 '20 at 14:46