How to setup .gitignore for Windows?

Easy.

  1. Make a file .gitignore using your text editor
  2. In there, write the file name you'd want to ignore
  3. You can use wildcard like: *.pyc ignoring any file with extension .pyc

If you use TortoiseGit or other Git software, it will be easier. There will be add to ignore list menu when you right click to a file.


It seems that for ignoring files and directories there are two main ways:

.gitignore

  • Placing .gitignore file into the root of your repo besides .git folder (in Windows make sure you see the true file extension and then make .gitignore.

  • Making global configuration %HOMEPATH%\.gitignore_global and running

    git config --global core.excludesfile %HOMEPATH%\.gitignore_global to add this to your git config.

Note: files tracked before can be untracked by running git rm --cached filename. This absolutely critical for repos that existed BEFORE you created the .gitignore

Repo exclude

For local files that doesn't need to be shared, you just add file pattern or directory to file .git\info\exclude. These rules are not committed, so are not seen by other collaborators in your project. These are machine specific configs.

Tags:

Windows

Git