Welcome to the thrilling world of ignore files where careers are made and repository sizes are kept under control. This short guide shows how to use .gitignore with GitLab so your repo does not become a graveyard of node_modules folders and accidental .env files. If you like clean repositories and fewer angry reviewers this is for you.
Start by creating a .gitignore at the root of your project. Add simple glob patterns that tell Git what to ignore. Common entries include
node_modules/
to avoid shipping thousands of tiny files.env
to keep secrets out of history*.log
to stop logs from cluttering diffsUse community templates for your language or framework so you do not have to guess every noisy file. GitHub and GitLab both offer starter templates that cover many common cases.
/build/
ignores the build output at the repository rootlogs/*.log
ignores all log files in the logs folder!.gitkeep
keeps an otherwise empty folder trackedRun git init
then git add .
to stage files. Git will happily track everything you tell it to. A good .gitignore prevents accidental bloat in version control and avoids phantom blame for files that should never have been tracked.
Commit with a clear message and push to your branch. For example
git commit -m 'Initial commit'
git push origin main
A tidy .gitignore makes GitLab diffs and merge requests less painful for reviewers and keeps your remote storage from ballooning.
If a file was already committed you need to remove it from the index while keeping the local copy. Run
git rm --cached path/to/file
git commit -m 'Remove tracked secret or large file'
That removes the file from future commits while leaving it on your workstation. If the file leaked sensitive data consider rotating secrets and, if necessary, rewriting history only after coordinating with your team.
Create a test file that matches one of your patterns and run git status
to confirm it is not staged. If things do not behave as expected use
git check-ignore -v path/to/file
This command shows which pattern caused the file to be ignored which is very useful for debugging confusing rules.
Remember that GitLab CI can still upload caches and artifacts even when files are ignored by Git. Check your .gitlab-ci.yml for cache and artifact paths and exclude patterns so CI does not send node_modules or temporary files to your remote storage.
git check-ignore -v
to see which rule matched a fileFollow these steps and your repositories will stay lean, reviewers will thank you, and future you will not cry when cloning a 10 GB project. If you still see trouble post a minimal reproducible example and someone in the team will heroically point out the pattern you forgot to add.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.