More with .gitignore


.gitignore file is used for ignoring files and  directory. We use regular expression for it. But we can use it for more than that. We can use it for allowing a certain type of files or folder.

Here are some examples:

  • To ignore any file (absolute path and relative path both works). 
/fol/desktop.ini
fol/desktop.ini
  • To ignore any directory. Relative path fol/ will ignore folder recusively in subdirectory also, while /fol/ will only ignore directory resides in root directory.
/fol/
fol/
  • To ignore any specific file extension
*.ini
  • To ignore everything. Absolutely there is no point in doing this. Wait for its usage.
*
  • To ignore everything but not a certain file. The (not) is used to save certain files from being ignored.
*
!.gitignore
  • To ignore everything but not a certain directory.
*
!fol/
  • To ignore everything but not directory
*
!*/
  • To ignore everything but not certain file type in all directory
*
!*/
!*.java


Sources:
https://stackoverflow.com/questions/8024924/gitignore-ignore-all-files-then-recursively-allow-foo
https://gist.github.com/hieblmedia/9318457

Comments