DEV Community

Cover image for Git Ignore Locally: Ignore Files in Local Copy
3 1

Git Ignore Locally: Ignore Files in Local Copy

The blog post is going to a short and sweet writeup about one of the git aliases that I have created in my gitconfig. I use this shortcut quite often and it could come in handy for developers using Git as version control.

.gitconfig is the file that stores the basic settings for Git installed on your machine. It includes your commit name and email. You can also set your diff and merge tool here, among other things.

Locations

For Windows

%USERPROFILE%\.gitconfig

For Mac

~/.gitconfig

Problem

Imagine you are working on a project. The project requires modifications to specific files to run on your machine. You do not want to commit these changes, but Git tracks these files.

These files will clutter the commit tree in your source control manager or when you do git status.

The above is just one scenario. There could be any reason for you to have some local modifications to files which you should not commit and like I said you don't want to commit them.

Solution

You can ignore these files locally without un-tracking them!

Add the following aliases to your .gitconfig file.

ignore = update-index --skip-worktree
unignore = update-index --no-skip-worktree
ignored = !git ls-files -v | grep \"^S\"

It gives you three Git shortcuts ignore (to locally ignore some files), unignore (to stop the local ignore on specific files), and ignored (to see the list of files you have ignored).

Execute any of the shortcuts, prefixed with git, in your terminal. Like below:

> git ignored

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay