1

I want to have two .gitignore files.

I would like to have two .gitignore files for my project. One is already committed to the repo. I do not want to change that file & at the same time I want to ignore some other files (We are a big team & strict code review practice stops us from committing .gitignore files to repo)

Can I point my repo to two ignore files? Or can I have a local gitignore file & a global gitignore file?

Can we even replicate this in some sandbox & see a live example online.

Hugo y
  • 1,421
  • 10
  • 20
ahmed
  • 540
  • 2
  • 18
  • 2
    You can add the extra ignored patterns to `.git/info/exclude`. It affects the current repository only and won't be added or committed. – ElpieKay Jul 30 '19 at 06:32
  • Refer https://stackoverflow.com/a/767213/6671004 – Shrey Garg Jul 30 '19 at 06:35
  • 2
    Possible duplicate of [How do you make Git ignore files without using .gitignore?](https://stackoverflow.com/questions/653454/how-do-you-make-git-ignore-files-without-using-gitignore) – phd Jul 30 '19 at 09:19
  • https://stackoverflow.com/search?q=%5Bgitignore%5D+local+.gitignore – phd Jul 30 '19 at 09:19

1 Answers1

2

Yes you can have a global .gitignore. You can do this by using the following commands.

touch ~/.gitignore

git config --global core.excludesfile ~/.gitignore

This will set your global .gitignore.

See: https://git-scm.com/docs/gitignore/2.22.0 for more details.

Edit: As suggested by @ElpieKay, if you want a project specific ignore on top of the .gitignore you can add them .git/info/exclude.

Yogesh_D
  • 17,656
  • 10
  • 41
  • 55
  • Can we add a file to ignore list (through .git/info/exclude) if it is already checked in to repo? – ahmed Jul 30 '19 at 16:06
  • @ahmed I would imagine no - just like if file were in .gitignore proper. First remove it from git version control with `git rm yourFile` then add `yourFile` to `.git/info/exclude`. – justin Feb 10 '23 at 11:18