Skip to content

Instantly share code, notes, and snippets.

@nrutman
Created May 13, 2019 14:27
Show Gist options
  • Save nrutman/92b971d592983f4b38af6c754e2acea0 to your computer and use it in GitHub Desktop.
Save nrutman/92b971d592983f4b38af6c754e2acea0 to your computer and use it in GitHub Desktop.
Creates a new git branch, pushes it to a remote, and links it as the upstream branch
#!/usr/bin/env bash
# Creates a new branch locally and links it to the upstream in a remote (defaults to origin)
BRANCH="$1"
REMOTE="origin" # default value...can be overridden with $2
# make sure a branch name was specified
if [ "$1" == "" ]; then
echo "Error: the branch name was not specified."
exit 1;
fi
# if a remote was specified, use that instead of origin
if [ "$2" != "" ]; then
REMOTE="$2"
fi
# creat the branch and the upstream
git checkout -b "$BRANCH" && git push -u "$REMOTE" "$BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment