Skip to content

Team git bash shortcuts

Jeremy Elbourn edited this page Jul 31, 2019 · 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 you have an https remote for upstream called upstream-http.

[alias]
	co = checkout
	br = branch
	df = diff
	dif = diff
	ca = commit -a
	c-p = cherry-pick
	dif = !git diff -- . ':(exclude)yarn.lock'
	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 = "!sh ~/scripts/github-pr-export.sh"
  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"

@jelbourn's git export script:

(assumes you've set up your remote to fetch pull requests)

#!/usr/bin/env bash

git push -f jelbourn $(git br-name)
git fetch upstream refs/pull/*/head:refs/remotes/upstream/pr/* > /dev/null
SHA=$(git rev-parse HEAD)
PR_BRANCH=$(git branch -ra --contains ${SHA} | grep 'pr/')
if [ "${PR_BRANCH}" = "" ]; then
  echo 'Create PR:'
  echo $(git url)/compare/master...jelbourn:$(git br-name)?expand=1
else
  PR_NUMBER=$(echo ${PR_BRANCH} | cut -d'/' -f4)
  PR_URL=$(git url)/pull/${PR_NUMBER}
  echo "Exported to ${PR_URL}"
fi