Git Cheat Sheet · Changes
Ignore files
echo <pattern> >> .gitignore
The .gitignore file, at the root of the repository, lists the files Git must ignore: dependencies, build files, logs, local settings. An ignored file no longer appears as untracked and is not included by git add -A.
What it does
Files matching a .gitignore pattern no longer appear as untracked.
A use case
Your editor creates a cache folder or .log files that you never want to commit.
Warning: No effect on an already tracked file: you must first remove it from the index (git rm --cached, in the terminal).
On the command line
*.log- Ignores all .log files, in all folders.
node_modules/- Ignores a folder, wherever it is.
/build- Ignores only the build at the root of the repository.
!important.log- Exception: tracks this file anyway.
git rm --cached <file>- Stops tracking a file already committed, without deleting it from disk.
git check-ignore -v <file>- Shows which line of which .gitignore ignores this file.
In Merathon
- Right-click an untracked file ("?") in "Unstaged".
- "Add to .gitignore" ignores this file, "Ignore this extension" all those of the same type, "Ignore this folder" its folder.
- Remember to commit the modified .gitignore.
Frequently asked questions
Why is my .gitignore not working?
The file is probably already tracked: .gitignore only applies to untracked files. Run git rm --cached <file>, then commit.
How do I ignore a file only on my machine?
Add the pattern to .git/info/exclude: it works like .gitignore but is not committed.