Skip file changes tracking in git

Article autor
October 6, 2023
Skip file changes tracking in git
Elixir Newsletter
Join Elixir newsletter

Subscribe to receive Elixir news to your inbox every two weeks.

Oops! Something went wrong while submitting the form.
Elixir Newsletter
Expand your skills

Download free e-books, watch expert tech talks, and explore open-source projects. Everything you need to grow as a developer - completely free.

Table of contents

So, you’re changing this one file for local development purposes only. Maybe it’s config, maybe some source file, but one thing is certain - you don’t want those changes to be committed. And what’s worse, .gitignore doesn’t work.

Yeah, .gitignore works only for files not tracked by git yet. So if there’s a config.ex file, which is a part of the project, and you don’t want to rebuild the repo from the foundation (which is rather a bad idea), then you probably want to reach for this one simple trick:

$ git update-index --skip-worktree config/config.exs

From git docs:

Skip-worktree bit can be defined in one (long) sentence: Tell git to avoid writing the file to the working directory when reasonably possible, and treat the file as unchanged when it is not present in the working directory.

Neither git status, git add . nor your IDE source control visualization should bother you anymore.

Ahh, and remember two more commands if you don’t want to google them later madly:

  1. This one shows all the files you marked with the --skip-worktree flag
$ git ls-files -v . | grep ^S
> S config/config.exs
  1. And that’s how you tell git to remove the flag:
$ git update-index --no-skip-worktree config/config.exs

Happy hacking!

Work with a team that keeps learning and building better software every day.

Related posts

Dive deeper into this topic with these related posts

No items found.

You might also like

Discover more content from this category

How to create and use custom shell commands?

Each of us had a situation, where we had to invoke a few, same commands each time. Making it once is not that problematic, but when we are supposed to repeat given operations, it may be better just to create one function that will handle it all.

How to install local npm package in a project

In some cases, like for testing purposes, you might want to use an npm package stored on a local machine. Here is how you can do that with one simple command.

How to run tests in Elixir IEx shell

Hey! Have you ever wondered about tests running inside the IEx shell? For a long time, I was convinced that it’s not really possible. And as it turns out - that’s not really straightforward. You won’t easily find information about that in the documentation.