Last updated 11 February 2016.


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.


    • 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


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


    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.


    1. $ git diffup effort.topic.patch


      • ./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.


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


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


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


    1. $ git rmbranch myfeature-sun


    • Due to the appearance of "branch" in the alias, your shell might autocomplete branch names.
  • git ac http://patch-url: Download and apply a patch in one command

    In ~/.gitconfig

    # Download and apply a patch.
            a = apply --index
            ac = "!f() { curl $@ | git a; }; f"


    git ac

Attributes (improved diff function context)

Git comes with support for smartly detecing the proper function context for diffs based on the language. However, it doesn't know by default which file contains which language. To change this, create an attributes file (in $HOME/.config/git/attributes, or $XDG_CONFIG_HOME/git/attributes if that variable is set) with the following contents:

*.engine   diff=php
*.inc      diff=php
*.install  diff=php
*.module   diff=php
*.php      diff=php
*.profile  diff=php
*.test     diff=php
*.theme    diff=php

For more information, see the Git attributes documentation.