Ignoring files in Git
Global, project and personal

tl;dr: We can tell git to ignore files using .gitignore and exclude.
- In the home directory, we can set the
global .gitignore - From within the project repository, there's the
project .gitignoreandpersonal excludefile (found within the local.gitfolder). - Rules in the subdirectories override the rules in the parent directories.
On .gitignore and exclude files
core.excludesfile- Global .gitignore
- Ignore files across all git repositories of the current user in the system.
- Example: Files related to the OS and code editor
Configure using
--globaloption- Below it's named
.gitignorebut it can be any file name (e.g..gitignore_global). By convention, this is saved in the same location as the global
gitconfig(in the home directory) but it can be in another location.nano ~/.gitignoreSpecify the path to the
.gitignorefilegit config --global core.excludesfile ~/.gitignore- Additional patterns can be appended using:
echo .DS_Store >> ~/.gitignore - ⏩ Set global .gitignore
- It's also possible to set values using
--systemand the--localoptions
- Below it's named
.gitignore- Project .gitignore
- Ignore files common across all copies of the current project repository.
- Example: File patterns related to the project and the programming language
- Node.gitignore
- config.json (because this contains the token)
echo config.json >> .gitconfig
- Version-controlled, committed and shared with anyone who clones the repository.
- There can be multiple
.gitignorein a repository but the convention is to place one in the top level directory. Same level as the local.gitfolder
.git/info/exclude- Personal exclude
- Ignore files within the current copy of the project repository.
- Example: File patterns related to personal workflow and development tools
- Personal commit.template saved in .gitmessage.txt
echo .gitmessage.txt >> .git/info/exclude
- Personal commit.template saved in .gitmessage.txt
excludeis a file located in the local.gitfolder. This file is not committed to the repository.
- ⏩ Display .git folder on Visual Studio Code
More .gitignore templates
- Github maintains a collection of .gitignore templates.
- Toptotal gitignore.io can be used to generate .gitignore files.



