.gitignore Syntax and Comments

.gitignore Syntax and Comments

Background

I haven’t had much of a need, for my personal stuff, for version control like git, but once I started using it, I kept running into issues with .gitignore seemingly being… ignored.

Here’s the quick answer: Inline comments that follow a pattern break the whole line. Keep comments on their own line.

Bad .gitignore syntax

# this comment is just fine
.git
.idea  # this inline comment doesn't make this folder ignored
**/__pycache__  # this inline comment doesn't make this folder ignored

Good .gitignore syntax

# this comment is just fine
.git
# .idea won't get ignored anymore
.idea
# **/__pycache__ won't get ignored anymore
**/__pycache__

References