Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nhed
Last active March 10, 2019 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhed/239aa94078b0b533d6f5 to your computer and use it in GitHub Desktop.
Save nhed/239aa94078b0b533d6f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# based on http://stackoverflow.com/a/18647857/652904
declare PROGNAME="${0}"
function Usage()
{
local -i EXITCODE=${1}; shift
echo "${@}" >&2
cat<<_EOF_ >&2
${@}
Usage:
${PROGNAME} <branchname> [git-branch-options]
git-branch-options are passed into git-branch after the branch name
_EOF_
exit ${EXITCODE}
}
BRNAME=$1; shift
[ -z "${BRNAME}" ] && Usage 1 "Missing branchname"
# exit on fail
set -e
git branch "${BRNAME}" "${@}"
git checkout "${BRNAME}"
git config branch."${BRNAME}".remote origin
git config branch."${BRNAME}".merge refs/heads/"${BRNAME}"
git config branch."${BRNAME}".rebase true
@nhed
Copy link
Author

nhed commented May 16, 2014

Kudos to Gregory McIntyre, for his underappriciated answer on http://stackoverflow.com/a/18647857/652904. It did exactly what I needed, I just made it into a full, slightly safer script that also allows specification of <start-point>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment