Last updated April 13, 2013.
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:
- Obviously, providing interdiffs for others.
- Doing atomic and clean commits.
- Writing proper commit messages.
(The shortlog can be copied 1:1 into an issue comment.)
- Your local branch
footracks the upstreammysandbox/foobranch.To configure/enforce this for existing branches:
git branch --set-upstream foo mysandbox/foo
Alias:
git config --global alias.diffup '!git log --oneline --reverse @{u}... && git diff 8.x... > $1 && git diff @{u} > interdiff.txt && echo'Explanation:
- 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)
- Creates a patch file containing all changes from the current branch since it diverged from
8.x. - Creates an interdiff between (old) upstream and the current local branch.
Usage:
$ 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 ...- 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:
- Deletes the local branch of the given name.
- If successful, deletes the remote branch of the given name.
Usage:
-
$ git rmbranch myfeature-sun
Benefits:
- Due to the appearance of "branch" in the alias, your shell might autocomplete branch names.