How to create .local.gitignore
that is not synchronized with Git?
-
Create the
.local.gitignore
filetouch .local.gitignore
-
Add it to
.git/info/exclude
(so Git applies it locally)echo ".local.gitignore" >> .git/info/exclude
-
Configure Git to treat
.local.gitignore
as.gitignore
git config --local core.excludesfile .local.gitignore
Now .local.gitignore
will work like a regular .gitignore
, but only for you.
How does it work?
.local.gitignore
is not added to the repository.- It is applied only locally on your computer.
- It works like
.gitignore
, but other developers don’t have it. - Git does not see this file thanks to
.git/info/exclude
.
Now you can add local files to it:
echo "my-secret-file.txt" >> .local.gitignore
echo "debug_logs/" >> .local.gitignore