# gt ignore

Sometimes there are files inside our local repository that we don't want to upload to the remote repository, such as keys, passwords or log files. The .gitignore file tells Git which files or folders to ignore. This means that Git won't track any changes made to those files and that they won't be uploaded to your remote repository.

It's recommended to have a .gitignore file so that when you run

$ git add .

Git won't upload any unwanted files by mistake. .gitignore is a plain-text file in which each line specifies a pattern to ignore. For example:

  • hello.* will match any file or folder whose name begins with hello (hello.txt, hello.log, hello.py)

  • doc/will match a folder named doc but not a file named doc. When you ignore a folder, Git will ignore any files or folders inside of it.

  • main.py will match any file named exactly main.py.

  • *.csv will match every csv file in your repository

It's important to note that the .gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected so if, for example, you committed a file named keys.py by mistake and later you add this pattern to the .gitignore file, nothing will happen. That is, the keys.py file will remain in the remote repo and Git will still track any modifications.

Gitutor provides an easy way to add files and folders to your .gitignore file so that you don't have to do it by hand! When you run

$ gt ignore

Gitutor will display a list with all the files and folders in your current directory. You only need to check all the files or folders you want to ignore, or uncheck any previously ignored file so that Git will begin to track it.

If you check a file or folder which was previously tracked by Git, Gitutor will run:

$ git rm --cached <filename>

This will remove said file form Git's tracked files and it will also remove the file from your remote repository, but not from your local one.