1

I have a repository with lots of bash scripts that I want to ignore. The problem is that the bash scripts don't have a .sh extension, but instead have #!/bin/bash at the start to signify that they are bash scripts. As a result, they cannot be identified by their file name.

I have tried putting *.sh in my .gitignore (and resetting the cache), but the bash scripts are still tracked.

Is there any way I can ignore these bash scripts in my .gitignore?

Daemon Beast
  • 2,794
  • 3
  • 12
  • 29
  • Have you tried listing them explicitly by name? – Stephen Newell Apr 20 '20 at 13:44
  • @StephenNewell There are loads, so that would not be possible. They are scattered in all of my dependencies. – Daemon Beast Apr 20 '20 at 13:44
  • Does this answer your question? [How do I add files without dots in them (all extension-less files) to the gitignore file?](https://stackoverflow.com/questions/19023550/how-do-i-add-files-without-dots-in-them-all-extension-less-files-to-the-gitign) – phd Apr 20 '20 at 18:41
  • https://stackoverflow.com/search?q=%5Bgitignore%5D+files+without+extensions – phd Apr 20 '20 at 18:41
  • @phd Those ignore all files without extensions, not only bash scripts without extensions. – Daemon Beast Apr 20 '20 at 18:46
  • `.gitignore` can only ignore files by name, not by content. It doesn't distinguish shell files unless shell files have specific extensions. – phd Apr 20 '20 at 18:47

1 Answers1

3
# Run in repo's root directory
grep -rl '^#!/bin/bash' . >> .gitignore

This will list all the files with bash shebang and append it to .gitignore

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50