Skip to content

[Fixed] Gitignore Not Working (3 Solutions for You)

GitHub has become a pacesetter in the coding and repository sharing field. Major businesses and companies rely on this platform.

However, the GitHub platform has experienced its hitches, and many complaints have been raised about gitignore not working in GitHub. The GitHub either ignored the gitignore, or it worked partially. Here is a discussion on what causes gitignore not to work and how to fix it.


What Causes Gitignore not to work

The leading cause for gitignore not working correctly is when the file has not been appropriately configured, making it not work in GitHub. GitHub can view every file in your directory and categorizes the files into three types:

  • The track, which is usually in the history section
  • The untracked which were not committed previously
  • The ignored are files that a user can set to ignore

Additionally, gitignore might not work because the underlying code has not met some necessary conditions.

Below are solutions that will help you in solving your gitignore problem.


1. Check the Gitignore File Format

You should confirm you created the gitignore file in the proper format for starters. gitignore files need ANSI coding. Using a notepad will save the file in UNICODE by default. This issue arises when creating a file using windows inbuilt tools. To solve this problem, you have to change the gitignore file format:

Step 1: Complete writing your gitignore file.

Step 2: Click on File and choose to save as from the submenu after making the new blank document changes.

Click on File and choose to save

Step 3: You will see a window popping up; select ANSI from the encoding drop-down menu. Ensure the save as type drop-down has All Files (**) selected.

Step 4: Remove the txt file extension and rename the file as gitignore.

Step 5: Choose the proper directory and press on save.

Choose the proper directory and save

Step 6: Taste the file again to confirm if gitignore is working.

If you previously saved the file in the UNICODE format, you should adequately save the contents in the ANSI format to detect the file by gitignore.


2. Check the File That You Are Ignoring

For gitignore to work effectively, you have to ensure that the file is not part of the repository. It will not be ignored if it is already in the repository, as gitignore can only overlook the untracked files.

Check gitignore Ignoring

To solve this issue, always check the repository and ensure that all the files you want to ignore are not added there. If any of the files are added to the repository, remove them, copy the file's contents and add its name to gitignore.


3. Re-add files to the Repository

If the files you are trying to ignore are already in the repository, remove everything from gitignore’s index and add them back to the repository. To be safe, you need to back up your codes in a safe place and then follow these steps:

Step 1: Type this command; git rm-r—cached, and hit Enter to execute the written command.

This command will unstage and remove the path to your files from the gitignore index.

Step 2: To re-add all the files back to the repository, use this command; git add; the specified files are the only ones you will be adding.

Step 3: To commit all the files back in the gitignore index, type git commit-m. “gitignore is now working.”

Re-add files to Repository

After following these steps, you can test whether the gitignore problem has been solved.


Conclusion

If you have an issue with gitignore, you should try checking the type of gitignore file format that you have used. Ensure that the structure is in Ansi; you can also check on the file you are ignoring by making sure it is not part of the repository yet to avoid being shunned by gitignore and finally re-adding the files back to the repository.

However, it would help if you remembered to copy the file's contents into another document for safe custody.