Skip to content

Team git bash shortcuts

Jeremy Elbourn edited this page Apr 12, 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
	added = diff --cached --name-only
	cam = commit -a --amend --no-edit
	br-name = "!git rev-parse --abbrev-ref HEAD"
	url = "!f() { URL=$(git config --get remote.upstream-http.url); echo ${URL/.git/}; }; f"
  sync = !git fetch upstream && git rebase upstream/master
  export = "!git push -f jelbourn $(git br-name) ; echo 'Create PR:'; echo $(git url)/compare/master...jelbourn:$(git br-name)?expand=1"
  submit = "!git push upstream $(git br-name):master"
  patch = "!f() { URL=$(git config --get remote.upstream-http.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