Gongey’s BlogDescribing the Indescribable World of The Gongey

All things Gongey

A Gongey is a special being. Having been created in the fiery furnaces of hell...wait...let me start over.
Back when collars were huge and pants were in the shape of bells I was born. The year was 1977. After 10 long months of gestation I was ready to join the world and make my contribution.
This blog is a record of my life. Good, bad and generally mundane!

For the past few weeks I have been searching and re-searching how to ignore files in Git. Yes I should have it memorized by now, sadly I don’t. Hence the need for this post.

As per the GitHub help page:

Ignoring files

From time to time there are files you don’t want git to track. There are a few methods of telling git what files to ignore.

.gitignore

If you create a file in your repository named .gitignore git will use its rules when looking at files to commit. Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename

This file can be committed into the repository, thus sharing the rule list with any other users that clone the repository.

Note that you can create a .gitignore in any subpath to have its rules applied at that path. Sometimes an empty .gitignore file is used as a placeholder for an empty path, for example to force git to generate a log/ path for your development environment to use.

GitHub maintains an official list of recommended .gitignore files at this public repository.

Global .gitignore

A global .gitignore file can also be very useful for ignoring files in every git repositories on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it. To add this file to your cross-repository configuration, run git config --global core.excludesfile ~/.gitignore_global

Here are some good rules to add to this file:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

You may also want to check out GitHub’s gitignore repository, which contains a list of .gitignore files for many popular operating systems, environments, and languages.

Repository exclude

Local per-repository rules can be added to the .git/info/exclude file in your repository. These rules are not committed with the repository so they are not shared with others. This method can be used for locally-generated files that you don’t expect other users to generate, like files created by your editor.

Ignoring versioned files

Some files in a repository, which are versioned (_i.e._ they can’t be git-ignored), are often changed, but rarely committed. Usually these are various local configuration files that are edited, but should never be committed upstream.

Git lets you ignore those files by assuming they are unchanged. This is done by running the git update-index --assume-unchanged path/to/file.txt command. Once marking a file as such, git will completely ignore any changes on that file; they will not show up when running git status or git diff, nor will they ever be committed.

To make git track the file again, simply run git update-index --no-assume-unchanged path/to/file.txt.

Links

This entry was posted in General and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Browse by Topic