Skip to content

Instantly share code, notes, and snippets.

@Sanne
Last active January 16, 2017 18:17
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 Sanne/8d4752322b1c9f1d6af03cec3597d943 to your computer and use it in GitHub Desktop.
Save Sanne/8d4752322b1c9f1d6af03cec3597d943 to your computer and use it in GitHub Desktop.
git-update
#!/bin/bash
# Temporarily checks out the "master" branch, fetches updates from upstream,
# pushes a copy to "origin" to keep it in synch, and then returns to the original
# branch.
#
# Released under the WTFPL license version 2 http://sam.zoy.org/wtfpl/
#
# Copyright (c) 2014 Sanne Grinovero
requireBranchName() {
branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
if [ "$?" -eq 128 ]
then
echo "Current branch not defined - aborting"
exit -1
fi
branch_name=${branch_name##refs/heads/}
}
requireBranchName
git fetch upstream
git checkout -q master
git pull --ff-only upstream master
git push origin master
git checkout -q ${branch_name}
echo "Master updated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment