Design a site like this with WordPress.com
Get started

How to refresh gitignore

After creating a .gitignore file in your repository and setting patterns to match files which you do not want Git to track, Git starts tracking repository files and respecting the patterns set in the .gitignore file after you run the git add command (For example git add .).

The problem is that if we later make some changes to the .gitignore file and then just run the git add command again, the changes made in the .gitignore file will not take effect.

For example if you later set in the .gitignore file that you want Git to start tracking a file which you previously set to be ignored, the file will still be untracked if you just run the git add . command.

This is because, the git cache needs to be cleared. I usually just do this with the git rm -r --cached . then after I run the git add . command to apply the .gitignore changes.

Things to note to do when making changes to .gitignore file

Here are just some points to note when making changes to the .gitgnore file to ensure Git is always tracking the right files.

  1. Make changes in .gitignore file.
  2. Run git rm -r --cached . command.
  3. Run git add . command
  4. git commit -m "Commit message" or just git commit or continue working.

What is really important here is step 2. And remember to just run git add . command before doing any commit.

Check ignored files

If you are using PhpStorm, the ignored files and folders will be automatically marked with the a color having #727238 as color code.

Use this tool to see the color and an approximate name for it.

You can also run the git status command to check if .gitignore is working as you want.

That is all for now. I hope short article was able to help you.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: