/github-for-non-tech

How to use .gitignore in a GitHub repo?

Learn how to create, configure, and update a .gitignore file in your GitHub repository with our step-by-step guide to keep your repo clean and secure.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to use .gitignore in a GitHub repo?

 
Step 1: Create a GitHub Repository
 
First, sign in to your GitHub account and click the New repository button. Provide a repository name and description. Choose whether it will be public or private, then click Create repository.

  • Open GitHub in your browser and log in.
  • Click the New button next to Your repositories.
  • Fill in the repository name, description (optional), and visibility.
  • Click Create repository.

 
Step 2: Clone the Repository Locally
 
Use Git to clone the empty repository to your local machine. Copy the repository URL from GitHub and run:


git clone https://github.com/your-username/your-repo.git
cd your-repo
  • Replace your-username and your-repo with your actual GitHub username and repository name.
  • This creates a directory named your-repo on your computer and sets it as the current working directory.

 
Step 3: Create a .gitignore File
 
In your project folder, create a new file named .gitignore. This file tells Git which files or directories to ignore when committing.


# Create the .gitignore file
touch .gitignore
  • You can use a terminal command like touch .gitignore (macOS/Linux) or type NUL > .gitignore (Windows).
  • Alternatively, create the file using your code editor’s file creation feature.

 
Step 4: Add Ignore Patterns to .gitignore
 
Open .gitignore in your text editor and list the files or directories you want Git to ignore. Each pattern should be on its own line. For example, to ignore log files, dependencies, and environment variables:


# Node.js dependencies
node\_modules/

# Production build output
dist/

# Environment variables
.env

# IDE or OS files
.vscode/
.DS\_Store
  • node_modules/ ignores all files in the node_modules directory.
  • dist/ ignores build artifacts.
  • .env ignores environment variable files containing secrets.
  • .vscode/ and .DS\_Store ignore editor and OS metadata.

 
Step 5: Verify .gitignore Is Working
 
Before committing, check which files are being tracked by Git:


git status
  • You should see that ignored files are not listed under Untracked files.
  • If you accidentally committed a file before adding it to .gitignore, remove it from Git tracking with:

git rm --cached filename.ext
  • Replace filename.ext with the name of the file or directory.
  • The --cached flag removes the file from tracking while leaving it on your filesystem.

 
Step 6: Commit and Push .gitignore
 
Once your .gitignore is configured, commit it and push to GitHub:


git add .gitignore
git commit -m "Add .gitignore with common patterns"
git push origin main
  • Use git add .gitignore to stage the file.
  • Use git commit to record the snapshot in the repository history.
  • Use git push to upload your changes to the main branch on GitHub.

 
Step 7: Update .gitignore Over Time
 
As your project grows, you might need to ignore additional files. Simply edit the .gitignore file, add new patterns, and repeat the commit and push process:


# Example: ignore log files
\*.log
  • After editing, run git status to confirm only desired files are tracked.
  • Stage and commit the changes with git add .gitignore and git commit.
  • Push updates to GitHub with git push.

 
Step 8: Use .gitignore Templates
 
GitHub maintains a collection of .gitignore templates for many languages and frameworks. You can copy from https://github.com/github/gitignore and paste the relevant file into your project. This ensures you start with best practices.

  • Browse the repository for templates like Node.gitignore or Python.gitignore.
  • Copy the contents into your project’s .gitignore.
  • Customize as needed for any project-specific files.

 
Conclusion
 
Using a well-configured .gitignore file keeps your repository clean by preventing unnecessary or sensitive files from being tracked. Regularly update it as your project evolves and leverage GitHub’s official templates to follow community conventions.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022