Useful git tips

This is a collection of useful git commands, aliases, tips and tricks that I’ve come across or been using. Feel free to contribute to this collection by adding a comment below.

Aliases for ignoring files

To prevent changes in already-commited files from being commited, you can update your index with the --assume-unchaged flag for the files that you don’t want to commit. Here are a couple of useful aliases for dealing with this.

ignore = !git update-index --assume-unchanged
unignore = !git update-index --no-assume-unchanged
ignored = !git ls-files -v | grep ^[a-z]

With these aliases you can use git ignore <file> to ignore a file, git unignore <file> to unignore a file, and git ignored to list files that are currently being ignored.

Warning: Adding a file directly with git add <file> will add the file regardless of this flag.

Source: http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html (comments)

Commit partial changes

If you want to only commit certain changes in a file, you can use the following command:

git add -p <files>

Receive a weekly update in your inbox

I'd very much appreciate it if you'd be interested in getting an email delivered directly to your inbox every Sunday morning at 9AM with a summary of my tech related blog posts from the last week. I will not in any way use your email address for anything else. That's a promise.

Leave a Comment