Skip to content

Instantly share code, notes, and snippets.

@jphastings
Created September 18, 2019 15:04
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 jphastings/127bb940aa65f81f0c50a6d9577b74de to your computer and use it in GitHub Desktop.
Save jphastings/127bb940aa65f81f0c50a6d9577b74de to your computer and use it in GitHub Desktop.
Git into merges your current branch into the given remote branch, first resetting your local version of the given branch to remote's version thereof. To be invoked with a deep southern accent.
#!/bin/sh
# Place in your path and invoke with a deep southern accent: `git into staging`
mergeinto="$1"
if [[ $(git status -s) ]]; then
echo "Your working directory is not clean, please commit or stash first."
exit 1
else
branch=$(git rev-parse --abbrev-ref HEAD)
git fetch > /dev/null
git checkout "$mergeinto"
git reset "origin/$mergeinto" --hard
output=$(git merge "$branch" --no-edit)
ecode=$?
if [[ $ecode == 0 ]]; then
echo "Successfully merged into $mergeinto"
git push origin "$mergeinto"
echo "Pushed $mergeinto"
git checkout "$branch"
else
echo "There were problems merging $branch into $mergeinto. To safely return to whence you came:"
echo "$$ git merge --abort && git reset origin/$mergeinto && git checkout $branch"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment