How to Create a Personal Gitignore
What if I want to save something in the repository without committing it? I’d have to add it to my repository’s gitignore. For a personal project, this is fine. However, on a large team, if everyone did that the gitignore can get bloated and irrelevant.
I needed a local gitignore so I can save files and directories in the shared repo without affecting others and this is how I did it.
In your terminal, cd to the repository where you want to make a local gitignore.
cd ~/Documents/my_repo
We want to edit the git config of the repository we’re in. The —-local
flag specifies that we’re editing the config of just this repository and the —e
flag tells git to edit the config. For more info on this, run git config
to see all of the options.
git config --local -e
This should bring you into vim mode looking at your local git config. Just make sure to add the excludesfile line under the [core] section and save it.
[core] ... (existing configurations)
excludesfile = ~/Documents/my_repo/.local_gitignore[remote "origin"] ... (existing configurations)[branch "master"] ... (existing configurations)
Great! Now you have a local gitignore! Git will read from this file to determine what to not to track. You can treat it just like your other gitignore. Any file or directory you put in here will get ignored. Including itself. So what I do is put .local_gitignore
at the top of my .local_gitignore so it won’t get tracked either!
Happy coding!