Skip to content

Instantly share code, notes, and snippets.

@devxoul
Last active January 27, 2021 08:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/a972ba0db2a25b989887 to your computer and use it in GitHub Desktop.
Save devxoul/a972ba0db2a25b989887 to your computer and use it in GitHub Desktop.
Git Push Me: Git push current branch to origin.
#!/bin/bash
# https://gist.githubusercontent.com/devxoul/a972ba0db2a25b989887/raw/f62353501becb274eb63c76b83fbcc01250a286d/git-pushme
# git push origin CURRENT_BRANCH
BRANCH=$(git branch --list | awk '{ if ($1 == "*") print $2 }')
while true; do
read -p "Push branch '$BRANCH' to origin? [Y/n] " -n 1 -r
echo
if [[ ${#REPLY} > 0 && $REPLY =~ ^[Nn]$ ]]
then
echo "Abort."
exit 1
fi
if [[ ${#REPLY} == 0 || $REPLY =~ ^[Yy]$ ]]
then
COMMAND="git push -u origin $BRANCH ${*:1}"
echo -e "Executing command '$COMMAND'"
$COMMAND
exit 0
fi
echo "Enter 'y' or 'n'."
done
@devxoul
Copy link
Author

devxoul commented Oct 20, 2014

Usage

$ git pushme
Push branch 'master' to origin? [Y/n] y
Executing command 'git push origin master'
Everything up-to-date
$ git pushme -f
Push branch 'master' to origin? [Y/n] y
Executing command 'git push origin master -f'
Everything up-to-date

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