Skip to content

Instantly share code, notes, and snippets.

@dylansmith
Created March 31, 2015 10:22
Show Gist options
  • Save dylansmith/0599351f9b4f6a044b44 to your computer and use it in GitHub Desktop.
Save dylansmith/0599351f9b4f6a044b44 to your computer and use it in GitHub Desktop.
A bash alias to push a local git branch for the first time with --set-upstream
#!/bin/bash
# place this in your .bash_aliases or similar
git_current_branch() {
git rev-parse --abbrev-ref HEAD
}
git_push_set_upstream() {
branch=`git_current_branch`
cmd="git push --set-upstream origin $branch"
echo "command: $cmd"
read -p "Are you sure (y/n)? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
eval $cmd
fi
}
alias gbc=git_current_branch
alias gpsu=git_push_set_upstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment