Git ignore

Posted under » Version Control on 28 Sep 2021

Personal Git ignore rules

You can also define personal ignore patterns for a particular repository in a special file at .git/info/exclude. These are not versioned, and not distributed with your repository, so it's an appropriate place to include patterns that will likely only benefit you. For example if you have a custom logging setup, or special development tools that produce files in your repository's working directory, you could consider adding them to .git/info/exclude to prevent them from being accidentally committed to your repository.

Global Git ignore rules

In addition, you can define global Git ignore patterns for all repositories on your local system by setting the Git core.excludesFile property. You'll have to create this file yourself. If you're unsure where to put your global .gitignore file, your home directory isn't a bad choice (and makes it easy to find later). Once you've created the file, you'll need to configure its location with git config

$ touch ~/.gitignore
$ git config --global core.excludesFile ~/.gitignore

You should be careful what patterns you choose to globally ignore, as different file types are relevant for different projects. Special operating system files (e.g. .DS_Store and thumbs.db) or temporary files created by some developer tools are typical candidates for ignoring globally.

You can refer to Github gitignore for ideas.

Ignoring a previously committed file

Before cleaning up your repository, you should conduct two important preparations:

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository.

#1 Remove the files from the index (not the actual files in the working copy)
$ git rm -r --cached .

#2 Add these removals to the Staging Area...
$ git add .

#3 and commit them!
$ git commit -m "Clean up ignored files"

Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file. You can omit the --cached option if you want to delete the file from both the repository and your local file system.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data