Git add all .tex files recursively

Cloning a completely fresh repo.

I now have a complex file structure with many different files copied to my local working directory. But now I just want to add only all .tex files to all subfolders. But the following doesn't work:

git add *.tex #error-message: fatal: pathspec '*.tex' did not match any files
git add /*tex #error-message: fatal: C:/Program Files (x86)/Git/*.tex: 'C:/Program Files(x86)/Git/*.tex' is outside repository


Working with git version on a Windows machine.

How to do it?


git add **/*.tex

works good.

Another approach: How can the .gitignore file be adjusted so that it ignores everything except .tex files? I tried the following in my .gitignore file and then did git add .

, but it didn't work.

#Ignore all files



Second update

Got working with the following .gitignore file:

#Ignore all files




source to share

1 answer

As you wrote you are on windows, the simplest solution looks like this:

  • run powershell
  • cd to the root of the repo
  • and run this command:

    ls -Include * .tex -Recurse | foreach {git add $ _}

I think it's pretty simple what it does.



All Articles