How to stop copy-paste and make .gitignore globally?
Tags: git, tutorial, productivity, beginners
Published: 2020-01-14 21:52:42

## 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](https://git-scm.com/docs/gitignore) 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](https://thepracticaldev.s3.amazonaws.com/i/8cgi9l431ibxq8oo66o6.jpg)

## 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:

```bash
# OS specific
.DS_Store
Thumbs.db

# IDE
.idea/
.vscode/

# Node.js dependencies
node_modules/

# Node.js logs
*.log

# Builds
build/
dist/

# ...
```

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`:

```bash
$ 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
```

- Second, add `.gitignore_global` file to `git` config:

```console
$ git config --global core.excludesfile ~/.gitignore_global
```

- 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

<a name=""></a>
## P.S.

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

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 projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv