Skip to content

Instantly share code, notes, and snippets.

@andersonba
Created April 27, 2017 17:53
Show Gist options
  • Save andersonba/a5816fc0cc7334d0fc5fadd9d6ca40f9 to your computer and use it in GitHub Desktop.
Save andersonba/a5816fc0cc7334d0fc5fadd9d6ca40f9 to your computer and use it in GitHub Desktop.
Git fetch, merge and push in one command
#!/usr/bin/env bash
MASTER="master"
if [[ "$1" != "" ]]; then
BRANCH="$1"
else
BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi
echo "> Fetching origin/$MASTER..."
git fetch origin $MASTER
echo "> Merging with $BRANCH"
git merge origin/master $BRANCH
echo "> Done"
read -r -p "Do you want to push this branch? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
echo "> Pushing $BRANCH to origin..."
git push origin $BRANCH
exit 0
;;
*)
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment