Last updated January 15, 2014.

Aliases

git aliases are a powerful way to streamline your most frequent git operations. Read a basic tutorial here. Git Immersion also has a section for aliases.

  • git diffup: Create full patch, interdiff.txt, and commit log in one shot for sandbox patches.

    Applies to:

    • Larger or more complex core patches, which are developed and improved in a sandbox branch.

    Assumptions:

    • You won't push commits upstream before you create a patch for a d.o issue.
    • You want to combine and enforce best practices:
      1. Obviously, providing interdiffs for others.
      2. Doing atomic and clean commits.
      3. Writing proper commit messages.
        (The shortlog can be copied 1:1 into an issue comment.)
    • Your local branch foo tracks the upstream mysandbox/foo branch.

      To configure/enforce this for existing branches:

      git branch --set-upstream foo mysandbox/foo

    Alias:

    git config --global alias.diffup '!git log --oneline --first-parent --reverse @{u}... && git diff 8.x... > $1 && git diff @{u} > interdiff.txt && echo'

    Explanation:

    1. Outputs the commit messages of all new commits that haven't pushed to upstream yet to the console/stdout. (ready to be copied 1:1 into an issue comment)
    2. Creates a patch file containing all changes from the current branch since it diverged from 8.x.
    3. Creates an interdiff between (old) upstream and the current local branch.

    Usage:

    1. $ git diffup effort.topic.patch

      creates:
      • ./effort.topic.patch
      • ./interdiff.txt

      and shows the log; e.g.:

      e20b52b Copied ConfigTest into Drupal\Core\...
      7f20970 Added generic ConfigThingie with ab...
      6b92dac Renamed ConfigThingie::load() into ...
    2. After updating the d.o issue, push your local changes into the upstream sandbox branch.
  • git rmbranch: Delete and prune a branch locally + remotely.

    Applies to:

    • Heavy branch users.

    Assumptions:

    • You (and no one else) needs the specified branch anymore.

    Alias:

    git config --global alias.rmbranch '!git branch -d $1 && git push origin --delete'

    Explanation:

    1. Deletes the local branch of the given name.
    2. If successful, deletes the remote branch of the given name.

    Usage:

    1. $ git rmbranch myfeature-sun

    Benefits:

    • Due to the appearance of "branch" in the alias, your shell might autocomplete branch names.