A Basic .gitignore
Create the file in the repository root:
# secrets and local settings
.env
# dependencies
vendor/
node_modules/
# logs and caches
*.log
storage/cache/Then commit it like any other file:
git add .gitignore
git commit -m "Add .gitignore"Lines starting with # are comments. Blank lines are ignored.
Pattern Rules
| Pattern | Matches |
|---|---|
*. | Any file ending in .log, in any folder |
/config. | Only config.php in the root |
build/ | Folders named build, anywhere |
logs/ | .log files directly in logs |
**/ | cache at any depth |
debug?. | debug1.txt, debugA.txt |
A pattern with a slash at the start or in the middle is relative to the folder of the .gitignore file. A pattern without one matches at any depth. A trailing slash matches folders only. You can also place a .gitignore in a subfolder; its patterns apply to that folder.
Negation with !
A line starting with ! re-includes something an earlier line excluded:
*.log
!install.logGit cannot re-include a file whose parent folder is excluded, because it never looks inside that folder. To keep one file in an otherwise ignored folder, ignore the folder's contents rather than the folder:
uploads/*
!uploads/.gitkeepStop Tracking a File Already Committed
Adding a committed file to .gitignore changes nothing: Git keeps tracking it. Check what is tracked, then remove the file from the index while keeping it on disk:
git status
git rm --cached .env
git commit -m "Stop tracking .env"For a folder, use git rm -r --cached storage/cache. Before you push, know two things:
- Other checkouts: when another clone or server pulls this commit, Git deletes the file there. Copy it aside on those machines first.
- History: the file stays in every earlier commit. If it held passwords or keys, change them; untracking does not make them secret again.
A Global Ignore File
Files your editor or operating system creates belong in a personal ignore file, not in every project:
git config --global core.excludesFile ~/.gitignore_globalPut patterns such as *.swp or .DS_ in that file. If you do not set the option, Git reads ~/.config/git/ignore when it exists (or the same file under $XDG_ when that variable is set). For patterns that apply to one clone only and should not be committed, use .git/info/exclude.
Find Out Why a File Is Ignored
git check-ignore -v storage/cache/page.htmlThe output names the ignore file, the line number, and the pattern that matched. No output means the file is not ignored. To list the ignored files and folders in the project:
git status --ignoredCommon Mistakes
- Rules in a subfolder: patterns in a subfolder's .gitignore are relative to that subfolder, not to the repository root.
- Wrong file name: the file is
.gitignore, with the leading dot. - Ignoring the lock file: files such as
composer.lockshould usually be committed, so every server installs the same versions.
Ignored files are also left alone by git stash unless you add -a. To set Git up on a new server, see how to install Git on Linux; to undo a commit that added the wrong file, see git reset explained.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations