Ignoring (local) config files with git and Sourcetree

Some files in a repository need to be versioned, but not committed to an upstream repository. This is how to achieve and how to create a Custom Action in Sourcetree for this task

Sourcetree Logo

The problem how to manage files like configuration files with github took me quite a while to figure out. It was until I stumbled across a stackoverflow answer where I found out about the update-index git command.

Some files in a repository change often but are 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. http://stackoverflow.com/a/18277622/1423758

The update-index command can be used with the option --assume-unchanged or --no-assume-unchanged, followed by the path to the file. Once a file is marked unchanged, git ignores any changes nor will it get committed.

$ git update-index --assume-unchanged path/to/file.txt
$ git update-index --no-assume-unchanged path/to/file.txt

Sourcetree

I for myself think it's easier and "saver" to use a GUI for git rather than the Terminal - for that reason, I prefer the app Sourcetree. Sourcetree provides the ability to define "Custom Actions", which can later be easily reused with right-clicking a file or folder.

Sourcetree Screenshot Custom Actions

Open the settings from Sourcetree and choose "Custom Action", now add a new command like in the Screenshot below:

Sourcetree Screenshot Custom Actions

Sourcetree Screenshot Custom Actions

List "assumed unchanged" Files

It can be helpful to see a list of all files which have been set "assumed unchanged". Use the command git ls-files -v in your Terminal for files that are marked as "assume unchanged".

Reading List