DEV Community

Cover image for How to stop copy-paste and make .gitignore globally?
Vic Shóstak
Vic Shóstak

Posted on • Updated on

How to stop copy-paste and make .gitignore globally?

Introduction

Hey! 👋 How're you today? Another "quick how to" article is here. I tell you some useful feature for your productivity with everyday coding and working with git.

What is .gitignore file?

Follow official description:

A gitignore file specifies intentionally un-tracked files that Git should ignore [...]

It means, .gitignore is your best friend, if you're don't want to push personal/environment/etc. files to your team's project repository on GitHub.

what is .gitignore file

What's actually included to your .gitignore file at every project?

Yep, both you and I, copy these lines from project to project, like a mantra:

# OS specific
.DS_Store
Thumbs.db

# IDE
.idea/
.vscode/

# Node.js dependencies
node_modules/

# Node.js logs
*.log

# Builds
build/
dist/

# ...
Enter fullscreen mode Exit fullscreen mode

And it's normal for all git beginners. But you can’t be a newbie all your life! It's time to grow and apply the best solution 👇

DRY (Don't Repeat Yourself)

In this complex world, it's so difficult to find a simple solution, but not for this task! We can define all of this "always copy-pasted lines" to global .gitignore file on your system.

Steps to reproduce

  • First, copy (for the last time, I promise) needed ignoring files and folders to your home directory ~/.gitignore_global:
$ sudo cat >~/.gitignore_global <<EOL

# OS specific
.DS_Store
Thumbs.db

# IDE
.idea/
.vscode/

# Node.js dependencies
node_modules/

# Node.js logs
*.log

# Builds
build/
dist/

EOL
Enter fullscreen mode Exit fullscreen mode
  • Second, add .gitignore_global file to git config:
$ git config --global core.excludesfile ~/.gitignore_global
Enter fullscreen mode Exit fullscreen mode
  • Finally, send link to this article to your teammates.

It's enough! Do this once and forget about excess files commits and copy-paste the same lines to .gitignore forever! 👍

Photo by

[Title] Yancy Min https://unsplash.com/photos/842ofHC6MaI
[1] Joshua Aragon https://unsplash.com/photos/EaB4Ml7C7fE

P.S.

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

❗️ You can support me on Boosty, both on a permanent and on a one-time basis. All proceeds from this way will go to support my OSS projects and will energize me to create new products and articles for the community.

support me on Boosty

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My main projects that need your help (and stars) 👇

  • 🔥 gowebly: A next-generation CLI tool that makes it easy to create amazing web applications with Go on the backend, using htmx, hyperscript or Alpine.js and the most popular CSS frameworks on the frontend.
  • create-go-app: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.

Other my small projects: yatr, gosl, json2csv, csv2api.

Top comments (0)