How to create a .gitignore file in GitLab |Video upload date:  · Duration: PT2M56S  · Language: EN

Learn how to add a .gitignore file in GitLab using the web UI add ignore patterns commit and keep unwanted files out of the repository

Quick summary

If your repo is starting to hoard build artifacts temporary logs or secret files you did not ask for then a .gitignore is your cleanup crew. This guide shows how to create edit and commit a .gitignore from the GitLab web UI so your repository stops tracking the stuff you never meant to track.

Why .gitignore matters

.gitignore keeps node_modules logs compiled assets and config files out of your commits. That keeps the history smaller and your CI less angry. It does not remove files that are already tracked though, so read the section on previously tracked files if you are cleaning up a mess.

Step by step in the GitLab web UI

Open the project and pick the branch

Go to your project in the GitLab web UI and select the branch you want to update. No wizardry here just the right project and branch. If you are working with others consider creating a feature branch and opening a merge request for review.

Create the .gitignore file

Click New file or open the Web IDE then enter the filename .gitignore. The editor will create a file in the chosen branch. If you prefer the Web IDE you get a nicer editor and a built in preview for some file types.

Add ignore patterns

Put patterns that match build artifacts temporary files and secret config. Use relative paths when you mean folders inside the repository. Example entries include

  • node_modules/
  • *.log
  • .env
  • dist/ or build/

Pattern rules follow standard gitignore behavior so a trailing slash means a directory and an asterisk is a wildcard. Keep project specific patterns inside the repo and personal OS noise in a global ignore file.

Commit the new file

Write a clear commit message. You can commit directly to the branch or create a new branch and open a merge request for review. The branch workflow helps avoid accidental overwrites and gives your teammates a chance to roll their eyes politely.

Verify that ignored files are not shown

Run a local git status or check the repository file list in GitLab. Newly ignored patterns should not show up as untracked files. Remember that files already tracked by Git will stay tracked until you remove them from the index.

Removing files that are already tracked

If large or sensitive files were already committed you need to remove them from the index and commit that change. For a single file run

git rm --cached path/to/file

Then commit and push. For many files you can script the removals or reset history with care and coordination.

Pro tip for personal noise

Keep your laptop and OS related clutter out of the repo by using a global ignore file. Configure it once on your machine with

git config --global core.excludesfile ~/.gitignore_global

Then list things like .DS_Store and Thumbs.db there so every repo on that machine benefits.

Quick checklist

  • Create .gitignore in the GitLab web UI or Web IDE
  • Add sensible ignore patterns for node modules logs builds and secrets
  • Commit to a branch or open a merge request for review
  • Verify with git status and the GitLab file view
  • Use git rm --cached for files already tracked
  • Use a global ignore for personal OS files

Follow these steps and your repository will stop hoarding junk. Your future self will send you a polite thank you email or at least a grateful commit message.

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.