[git] Comments in .gitignore?

Can you write comments in a .gitignore file?

If so, should the line be preceded with a # or some other indicator?

This question is related to git comments gitignore

The answer is


Yes, you may put comments in there. They however must start at the beginning of a line.

cf. http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files

The rules for the patterns you can put in the .gitignore file are as follows:
- Blank lines or lines starting with # are ignored.
[…]

The comment character is #, example:

# no .a files
*.a

Do git help gitignore

You will get the help page with following line:

A line starting with # serves as a comment.

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to comments

Way to create multiline comments in Bash? Jenkins: Can comments be added to a Jenkinsfile? /** and /* in Java Comments Where is the syntax for TypeScript comments documented? Multiple line comment in Python How do I add comments to package.json for npm install? How to comment multiple lines with space or indent Is there a shortcut to make a block comment in Xcode? How to comment and uncomment blocks of code in the Office VBA Editor Which comment style should I use in batch files?

Examples related to gitignore

Gitignore not working How to add files/folders to .gitignore in IntelliJ IDEA? Apply .gitignore on an existing repository already tracking large number of files Ignore .classpath and .project from Git .gitignore all the .DS_Store files in every folder and subfolder Correctly ignore all files recursively under a specific folder except for a specific file type What should be in my .gitignore for an Android Studio project? Commit empty folder structure (with git) How to remove files that are listed in the .gitignore but still on the repository? What to gitignore from the .idea folder?