★ .gitignore without .gitignore
• 239 words • 2 min • updated
.gitignore is the canonical way to exclude files from your git repository.
In some situations, however, you may want to exclude files without adding them
to .gitignore, because they are only relevant to you, as opposed to your
teammates.
Common examples:
.ackrc: exclude file patterns from search withack– not everyone in your team may useackat all.envrc:direnvintegration to automatically run a couple of commands whenevercd‘ing to within the repository – not everyone in your team may usedirenvat all
…and so on.
Is there a way to have a “personal” .gitignore file? Yes, in fact, many ways!
1) Per repository #
Use the .git/info/exclude file instead of .gitignore. Edits in this file are
not tracked by version control. The documentation says:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.ackrc
.envrcFor example, I could add .ackrc to it.
2) git update-index
#
% git update-index --assume-unchanged .ackrc .envrcIf you make a mistake, it can be reversed with --no-assume-unchanged.
3) Globally #
This approach takes effect in all repositories.
Set core.excludesFile in
your ~/.gitconfig:
git config --global core.excludesFile '~/.gitignore'Now populate it as you normally would your repo .gitignore.