You can create a global .gitignore
:
git config --global core.excludesfile ~/.config/git/ignore
for instance; see Global Git ignore for much more about this.
Note, however, that in many cases, you should not do this. (This same idea is captured in the second answer on that page, which is not the accepted answer.)
For files that are created by something you do, that won't be created for other people doing work in the same project, a global .gitignore
is appropriate. For instance, suppose that all of your coworkers use the vim or emacs or sublime editor, but you use your own personal editor, perhaps called Frank's Editor, and it creates backup files named .frank.<name>
.
You would want all your Git repositories to ignore .frank.*
as those are your editor backups. They're not Bob's editor backups, which are *.~
because he uses emacs, and they're not Carol's .*.swp
vim temporaries. Your project shouldn't ignore *.~
either—that should be in Bob's global ignore, and Carol should have .*.swp
in her global ignore.
But if your project has a sandbox/
subdirectory that the project uses, that you, Bob, and Carol will all have in your project—well, that file-name should be in the project's .gitignore
file, so that it's ignored in your clone, in Bob's clone, in Carol's clone, and in every other clone anyone ever makes, because that project's .gitignore
gets cloned along with the project.