Questions tagged [gitignore]

.gitignore is a file that lists files, directories, and/or path patterns that Git should not include as part of a repository.

.gitignore is a file that lists files that should not include as part of a repository. It is typically used on binaries, temporary files, and packages.

For questions that are specific to Git's ignore mechanism, such as ignore-file syntax, use this tag. For VCS-agnostic questions, such as whether certain types of files should be checked into source control, use the tag.

Gitignore grammar

.gitignore interprets direct filenames and wildcards (both of which are recursive, front and back),

file.name   # Will match file.name, foo/file.name, foo/bar/file.name, etc.
*.tmp       # Will match out.tmp, foo/out.tmp, etc.
cache/*.bak # Will match cache/out.bak, foo/cache/out.bak, etc.

This recursive behavior can be stopped by adding a leading / to the line.

/file.name # Will only match toplevel file.name
/*.tmp     # Will only match toplevel tmp files
/cache/*.bak # Will only match bak files directly under cache

.gitignore will also do simple character classes.

foo.[abc] # foo.a, foo.b, and foo.c

It uses the # to denote comments.

# This comment goes until the end of the line

Certain files can also be excepted from wildcards by using the ! syntax.

# Ignore all *.config files except the default that ships
*.config
!default.config

It is imperative to note that gitignore uses the unix fnmatch style patterns to ignore files.

See the man page for more details.

To know which rule of which .gitignore is ignoring your file, use git check-ignore (since Git 1.8.3.3, July 2013):

git check-ignore -v -- path/to/your/file

Tools and examples

2935 questions
7951
votes
33 answers

How do I make Git forget about a file that was tracked, but is now in .gitignore?

I put a file that was previously being tracked by Git onto the .gitignore list. However, the file still shows up in git status after it is edited. How do I force Git to completely forget the file?
Ivan
  • 97,549
  • 17
  • 50
  • 58
2803
votes
21 answers

Ignore files that have already been committed to a Git repository

I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?
trobrock
  • 46,549
  • 11
  • 40
  • 46
2553
votes
6 answers

What are the differences between .gitignore and .gitkeep?

What are the differences between .gitignore and .gitkeep? Are they the same thing with a different name, or do they both serve a different function? I don't seem to be able to find much documentation on .gitkeep.
Matty
  • 33,203
  • 13
  • 65
  • 93
2536
votes
30 answers

Make .gitignore ignore everything except a few files

I understand that a .gitignore file cloaks specified files from Git's version control. How do I tell .gitignore to ignore everything except the files I'm tracking with Git? Something like: # Ignore everything: * # Do not ignore these…
Andrew
  • 36,541
  • 13
  • 67
  • 93
1793
votes
14 answers

How do I configure git to ignore some files locally?

Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my…
Bjorn
  • 69,215
  • 39
  • 136
  • 164
1730
votes
38 answers

.gitignore is ignored by Git

My .gitignore file seems to be being ignored by Git - could the .gitignore file be corrupt? Which file format, locale or culture does Git expect? My .gitignore: # This is a comment debug.log nbproject/ Output from git status: # On branch master #…
Matt Parkins
  • 24,208
  • 8
  • 50
  • 59
1706
votes
32 answers

How can I Remove .DS_Store files from a Git repository?

How can I remove those annoying Mac OS X .DS_Store files from a Git repository?
John Topley
  • 113,588
  • 46
  • 195
  • 237
1505
votes
20 answers

Ignoring directories in Git repositories on Windows

How can I ignore directories or folders in Git using msysgit on Windows?
sf.
  • 24,512
  • 13
  • 53
  • 58
1451
votes
16 answers

Ignoring any 'bin' directory on a git project

I have a directory structure like this: .git/ .gitignore main/ ... tools/ ... ... Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it…
Ben Hymers
  • 25,586
  • 16
  • 59
  • 84
1421
votes
20 answers

.gitignore exclude folder but include specific subfolder

I have a folder application/, which I add to the .gitignore. Inside the application/-folder there is a folder application/language/gr. How can I include this folder? I've tried this: application/ !application/language/gr/
chchrist
  • 18,854
  • 11
  • 48
  • 82
1393
votes
42 answers

How to create a .gitignore file

I need to add some rules to my .gitignore file. However, I can't find it in my project folder. Isn't it created automatically by Xcode? If not, what command allows me to create one?
Luca
  • 20,399
  • 18
  • 49
  • 70
1385
votes
32 answers

What should be in my .gitignore for an Android Studio project?

What files should be in my .gitignore for an Android Studio project? I've seen several examples that all include .iml but IntelliJ docs say that .iml must be included in your source control.
respectTheCode
  • 42,348
  • 18
  • 73
  • 86
1287
votes
22 answers

.gitignore for Visual Studio Projects and Solutions

Which files should I include in .gitignore when using Git in conjunction with Visual Studio Solutions (.sln) and Projects?
Martin Suchanek
  • 3,006
  • 6
  • 31
  • 31
1233
votes
13 answers

Global Git ignore

I want to set up Git to globally ignore certain files. I have added a .gitignore file to my home directory (/Users/me/) and I have added the following line to it: *.tmproj But it is not ignoring this type of files, any idea what I am doing wrong?
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
1099
votes
2 answers

How to .gitignore all files/folder in a folder, but not the folder itself?

I want to check in a blank folder to my Git repository. Effectively, I need to ignore all of the files and folders within the folder, but not the folder itself. How can I do this? What should I put in my .gitignore file? For those wondering why I…
Aron Woost
  • 19,268
  • 13
  • 43
  • 51
1
2 3
99 100