Skip to content

Team git bash shortcuts

Jeremy Elbourn edited this page Feb 9, 2016 · 9 revisions

Team git / bash shortcuts

This is a collection of team members' git and bash shortcuts that other may (or may not) find useful.

@jelbourn's .gitconfig aliases

Replace jelbourn with the name of your github fork. Assumes the main repo is upstream.

[alias]
	co = checkout
	br = branch
	df = diff
	dif = diff
	ca = commit -a
	ri = git rebase -i upstream/master
	cam = commit -a --amend --no-edit
	br-name = "!git rev-parse --abbrev-ref HEAD"
  sync = !git fetch upstream && git rebase upstream/master
  export = "!git push -f jelbourn $(git br-name)"
  submit = "!git push upstream $(git br-name):master"
  patch = "!f() { URL=$(git config --get remote.upstream.url); curl -L ${URL/.git//pull/$1.patch} | git am; }; f"

Pull request merge function

Bash function to patch a pull request into your local. Assumes the main repo is upstream. Originally written by @pkozlowski-opensource, modified by @jelbourn

# Merge locally a pull request from GitHub; amends the commit message to include PR number
# Usage: `ghpr 1234`
function ghpr() {
    pr=${1:?"Pull request number is mandatory"}
    remote_url=$(git config --get remote.upstream.url)
    pr_patch_url=${remote_url/.git//pull/$1.patch}
    echo ${pr_patch_url}
    curl -kL ${pr_patch_url} | git am -3 && git commit --amend -m "$(git show --format=%B HEAD -s)

Closes #${pr}"
}
Clone this wiki locally