Advanced Git Operations

Tagging

References:

Todo

Discuss tagging (annotated vs. non-annotated).

Aliases

You can create aliases for git commands that you use often to save you some typing.

I have added the following aliases to my ~/.gitconfig file:

[alias]
    st = status
    br = branch
    co = checkout
    ci = commit -s

Aliases are optional. Use them if you find them useful.

More info:

$ git help config                # Search for 'alias'

References:

Diff Tool and Merge Tool Configuration

Using a diff tool or a merge tool is almost required when viewing complicated diffs or attempting to resolve a difficult merge conflict. Trying to resolve a difficult merge manually in your editor is madness and will likely result in an incorrect merge. Merge conflicts can be hard to resolve, so do yourself a favor and spent the time to find a merge tool that works for you and learn how to use it. You will be happy that you did.

Various diff tool and merge tool options are available:

There are many other options, but the above are the ones that I have tried.

Having tried all of the above, I have found kdiff3 to work the best for me.

To configure git to use kdiff3 when running git mergetool or git difftool, I added the following to my ~/.gitconfig file:

[merge]
    tool = kdiff3
[mergetool]
    keepBackup = false
[mergetool "kdiff3"]
    cmd = /usr/bin/kdiff3 $BASE $LOCAL $REMOTE -o $MERGED
    trustExitCode = false
[diff]
    tool = kdiff3
    renames = copies
[difftool "kdiff3"]
    cmd = /usr/bin/kdiff3 $LOCAL $REMOTE

If you wish to use another tool, this may work with some tweaking.

Splitting Directories out of a Repository

Todo

Show how to split a repo in to multiple repos using git subtree split.

Working with multiple Repositories

More often than not, you will be working on a product that is built from multiple git repositories (Google Android is an extreme example of this). Fortunately, there are tools that can help make working with many repositories easier.

Google Repo

Google Repo makes cloning and managing a group of git repositories easier through the use of an XML manifest file. The manifest file lives in its own git repository which can be branched and tagged to represent a branching and tagging of the group as a whole.

Using Google Repo:

If you need to write or maintain a manifest file, you’ll need to read this:

Here’s an example project which uses a Google Repo manifest file:

Git Multi

The git-multi is an enhancement to git which allows you to run a git command on multiple repositories at the same time. Particularly useful for me are the following:

$ git multi status
$ git multi grep 'some-stuff'

My implementation of git-multi knows how to use Google Repo manifest files to determine which repos to operate on, although it can also work without Google Repo: