Skip to content

Instantly share code, notes, and snippets.

@rud
Forked from reinh/hack.sh
Created May 4, 2009 19:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rud/106620 to your computer and use it in GitHub Desktop.
Save rud/106620 to your computer and use it in GitHub Desktop.
#!/bin/sh -x
# Exit if any error is encountered:
set -o errexit
# git name-rev is fail
CURRENT=`git branch | grep '\*' | awk '{print $2}'`
git checkout master
git pull --rebase origin master
git checkout ${CURRENT}
git rebase master
@lauriro
Copy link

lauriro commented Jan 2, 2011

you could use just "git pull --rebase origin master" on your custom branch

@rud
Copy link
Author

rud commented Jan 2, 2011

@lauiro: true, but I'm doing this multiple times every day, so at least an alias for repeated commands makes sense. On top of that, this hack-script means the master branch is correctly tracking origin/master, so when it is time to ship the changes, nothing special has to be done.

@rud
Copy link
Author

rud commented Jan 5, 2011

.. as opposed to the local master branch not being updated when you do "git pull --rebase origin master" while positioned on a local branch. It can get a tiny bit confusing when your local feature branch diverges from the local master, so that's why both master and feature branc are updated by this script.

@lauriro
Copy link

lauriro commented Jan 9, 2011

agree, I have in .gitconfig:
up = !sh -c 'CUR=$(git branch | grep ^*) && git checkout ${1:-"master"} && git pull && git checkout ${CUR:2} && git rebase ${1:-"master"}' -

but I do not use it often.
(rebasing by default: git config --global branch.master.rebase true)

@joefiorini
Copy link

You can use set -e at the top of your script and clean up the || exit 1s at the end of each line.

@rud
Copy link
Author

rud commented Feb 22, 2011

Hi joefiorini,

Thank you for the tip, I've updated the gist as suggested. Much cleaner that way. Aah, proper error handling.

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