DEV Community

AK DevCraft
AK DevCraft Subscriber

Posted on • Edited on

1

Untrack existing Git file

How would you stop tracking future changes in an existing Git repository file, but do not want to delete that file from the repository?
git rm --cached is the command that’ll do the trick, however, it needs to be done in following way.

Syntax

git rm --cached filename
Enter fullscreen mode Exit fullscreen mode

Steps with example

Update the .gitignore file to include the filename, stage and commit .gitignore file.

ak@--mac git-useful-commands % echo "db.config" >> .gitignore
ak@--mac git-useful-commands % git add .gitignore 
ak@--mac git-useful-commands % git commit -m "Update .gitignore"
Enter fullscreen mode Exit fullscreen mode

Now make some edits and stage the file that you want to remove from future tracking. Later, remove the file from staging and commit it

ak@--mac git-useful-commands % git add db.config 
ak@--mac git-useful-commands % git rm --cached db.config
ak@--mac git-useful-commands % git commit -m "untrack db config file"
Enter fullscreen mode Exit fullscreen mode

Now, the file will remain in the repository, but future changes won't be tracked.

Happy Coding!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay