Platforms like these have their technicalities and issues. One specific problem which the coders experienced was that .gitignore was not working in GitHub. The platform either ignored the .gitignore or worked partially. It is interesting to note that the problem might be a little different in each case since each case is a completely different scenario. However, the solutions which we list will contain fixes which will work universally.

What is .gitignore?

Git (or GitHub) sees every file in your working directory. It characterizes each file as one of the three:

Tracked: These files are either committed or staged previously in history.Untracked: These are the files which haven’t been previously staged or committed.Ignored: These are the files which the user himself told Git to ignore completely.

These ignored files might vary scenario to scenario and are mostly machine generated files or build artifacts. This is the common practice; you might be ignoring various other files according to your own needs. Some examples of these files are:

Compiled code: These files are usually with the extension .class, .pyc, .ccp etc.Hidden system files: These are files which are used by the system for its operations but are hidden from plain view, for example, DS_Store or Thumbs.db, etc.Build output directories: These are mostly of the directories of /bin, /out, etc.Dependency caches: These files might be the contents of /node or /packages modules.IDE Configuration files: These are config files which are mostly created or managed by your IDE software.Files generated at runtime: There are some programs which create files at run time. If either such code is run, some files might be generated at run time in your working folder and you might ignore them in Git.

Whichever file you wish to ignore is tracked in a special file named as .gitignore which is mostly checked in the root of your working repository. According to the official documentation of GitHub on the subject, there is no specific gitignore command. Instead, you have to manually edit the file which you wish to ignore. The .gitignore file contains patterns which are matched against the file names in your working repository and these are used to help determine whether a specific file should be ignored or not.

What causes .gitignore not to Work?

The .gitignore feature might be working perfectly but you might not have configured it properly. In all of our surveys, we came to the conclusion that the module was indeed working. The reason why coders are unable to use the feature is mostly because they haven’t properly configured the file or there are some conditions which are not being met in the underlying code. Here are some solutions which might work for you. Each solution might not be applicable in your case so make sure that you switch to the next one if the initial conditions are not being met.

Solution 1: Checking .gitignore File

An interesting case came forth where we saw that the .gitignore file was created in the wrong format. This particular issue occurred when users created the file using the default application of Notepad in Windows OS. It turns out that Notepad writes the file in Unicode instead of ANSI format. In this solution, we will save the changes of Notepad in the correct format of .gitignore and see if this fixes the problem. Note: You have to remove the extension of .txt from the file when you create a new file using the Notepad. Developers should abstain from using the default Notepad in Windows. Instead, you should use proper ‘programmers’ notepad. Some examples include Notepad++ etc. In those, you will not have issues like these. Note: If your file is already saved in UNICODE format, you should save the contents in ANSI format properly if you want your file to be detected properly by Git.

Solution 2: Checking the File you are trying to Ignore

Another condition on which .gitignore works is that your file should not be part of the repository yet. This is a very essential aspect as if this is true, the file will not be ignored as it is already added to the repository. Git cannot ignore that even if you place its name or rule in the .gitignore file. So in essence, Git only ignores untracked files. You should look at your structure (repository) and make sure that the file which you are currently trying to ignore is not added to the repository. If it is, you would have to remove the file from the repository and after the latest changes are committed, add its name to .gitignore (you can also copy the contents of the file and after deleting it, replicate it with a different name).

Solution 3: Re-adding Files to Repository

If you have already added rules into .gitignore but the files that you want to ignore are already added, we can re-add the files. Adding means that we will remove everything from Git’s index and then add everything back into your repository again. When we add files again from scratch, the rules will be kept in mind which you have added in .gitignore and only the correct files are added. Note: You should back up your code somewhere else as well before performing this solution. It is always good to have a backup just in case. Now inspect your files and see if the issue is resolved and you can use .gitignore again without any issues.

[Fixed] Squad Game Mic Not Working (9 Working Methods)Fix: Search Not Working in Outlook 2010FIX: CTRL + TAB Hotkey Combination Not Working on a Computer with an NVIDIA GPUHow to Fix Your Laptop’s Touchpad Not Working Fix  Gitignore is not Working - 91Fix  Gitignore is not Working - 66Fix  Gitignore is not Working - 18