Sitemap
Akhila Korthiwada

Akhila Korthiwada

Understanding File Tracking in Git (Tracking, Untracking & .gitignore)

3 min readMar 27, 2026

--

Press enter or click to view image in full size

Hello, Welcome to Day 13 of my DevOps learning journey!

In this Day 13 learning journey, we will clearly understand:

  1. What tracking files means in Git
  2. How Git handles untracked files
  3. How to stop tracking files safely (untracking)
  4. Why .gitignoreis important in real projects

Introduction

While working on a real project, not every file should go into Git.

Some files you must track (like code),
Some you should ignore (like logs, temp files),
And sometimes… you accidentally track something you shouldn’t

That’s where today’s concepts come in:
Tracking
Untracking
.gitignore

What is File Tracking in Git?

In Git, tracking means Git is actively monitoring a file for changes.

Simple Understanding:

If a file is tracked → Git knows its history
If a file is untracked → Git ignores it completely

Imagine you just joined a team working on a backend project. On Day 1, your project folder looks like this:

project/
├── app.py
├── config.env
├── debug.log

You start building features, fixing bugs, and saving your work. Now Git comes into the picture.

Tracking Files

You wrote some important code in app.py.

Now you tell Git: This file is important, Track every change from now on. For that Run the following command

git add app.py
git commit -m "Added main application logic" app.py

Now, what happens? Git started tracking app.py Every change you make now is recorded in history. So if something breaks later, you can always go back

But Here’s the Twist

Your folder also has:

  • config.env → contains passwords
  • debug.log → just temporary logs

Do you want Git to track these?
❌ Definitely NO

But imagine… you accidentally did this:

git add .
git commit -m "Added all files"

Now even your secrets are tracked means config data and logs are also tracked. Now comes the concept of Untracking file sin GIT

Untracking Files

Now you realize the mistake. You tell Git: Hey, stop tracking this file… but don’t delete it from my system by running the following command

git rm --cached config.env
git rm --cached debug.log

What happens now? Git forgets the file, but the file still exists in your project folder.

Get Akhila Korthiwada’s stories in your inbox

Join Medium for free to get updates from this writer.

This is called Untracking

Tracking →Git is watching and saving changes

Untracking →Git stops watching, but file stays

Untracked file →Git never started watching it

Tracking and untracking is like deciding what matters in your project history.

Now you untracked your files by running rm — cached command, But here’s the problem

Next time you run git add .

Git will try to track those files AGAIN!

Don’t worry, Now we have a solution called .gitignore

What is .gitignore?

The .gitignore file tells Git which files and folders to ignore (not track).

This is useful for keeping log files, temporary files, build artifacts, or personal files out of your repository.

When to Use .gitignore

  • When you want to keep sensitive, local, or unnecessary files out of your repository
  • When sharing a project with others and want to avoid cluttering Git history
  • When working with build tools or editors that create extra files

Create a .gitignore File

  1. Go to the root of your local Git repository.
  2. Create a file named .gitignore:
touch .gitignore #creates a hidden file called gitignore

So, Now if you want to untrack some files you keep them in this file

The .gitignore file itself is tracked by Git, so everyone using the repository ignores the same files.

Now open git ignore file and write those files you don’t want to track

vim .gitignore #opens gitignore file

when the file is open just give

# Ignore log file
debug.log

This tells Git: No matter what… NEVER track these files again

Next time if you want to keep track of these files , just remove that file name from .gitignore file.

Conclusion

Day 13 was all about gaining control over how files are handled in Git — understanding tracking, untracking, and using .gitignore effectively. These concepts are not just commands, they shape how clean, secure, and manageable your project repository becomes.

In the next blog, we will explore one of the core concepts in Git — branching, which plays a key role in managing parallel development.

Thank you so much for taking the time to read my blog! 🌼✨

See you in next learning blog!!

--

--