How to .gitignore after commit

2 min read
Hakan Budak
Mar 23, 2023

Hello everyone, my dear readers. I haven’t been with you for a long time. This is my first post to you after the earthquake disaster in our country. In this article, I will tell you how to add .gitignore post commit.

Adding a file that shouldn’t be added to git like me. If you tried to add .gitignore later and failed, don’t worry :) Let me share all the details of my experience with you.

Here are the steps you can follow:

1- Remove the file from your local repository using the following command:

-git rm --cached <FILE_NAME>

This will remove the file from the repository but keep it in your local file system.

2-Perform the uninstall using the command:

-git commit -m "Remove <file_name> from repository"

This will create a new commit that removes the file from the repository’s history.

3- Add the file name to the .gitignore file to ensure it is not tracked in future commits.

-echo "<file_name>" >> .gitignore

This will append the file name to the end of the .gitignore file.

4- Commit the .gitignore file with the updated file name using the command:

-git add .gitignore

-git commit -m "Ignore <file_name> in future commits"

This will create a new commit that includes the updated .gitignore file.

5-SuperNOTE: If no solution works. Use this method which is my final solution

-git check-ignore -v /path/to/file

-git rm --cached /path/to/file

Note: Removing a file from the repository’s history can have consequences if other contributors have pulled or cloned the repository, so be sure to communicate any changes to the team.

Thank you for reading . See you in my next post :)


From the blog

The latest industry news, interviews, technologies, and resources.
No items found.

Get Top landing pages by session

You don't need worry about performance changes or missing opportunities, in one email, heybooster Google Analytics Weekly Report summarizes all.