Skip to content

Instantly share code, notes, and snippets.

@wederbrand
Created January 11, 2013 08:29
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 wederbrand/4508945 to your computer and use it in GitHub Desktop.
Save wederbrand/4508945 to your computer and use it in GitHub Desktop.
git post checkout hook for gerrit
#!/bin/bash
BRANCH=`git symbolic-ref -q HEAD`
if [ "$BRANCH" == "" ]; then
BRANCHNAME=master
else
BRANCHNAME=`basename $BRANCH`
fi
# remote should always be origin
git config branch.$BRANCHNAME.remote origin
# set up rebase, even for local branches (since we now treat them as tracked)
git config branch.$BRANCHNAME.rebase true
# set merge to be refs/heads/master if empty
MERGE=`git config --get branch.$BRANCHNAME.merge`
if [ "$MERGE" == "" ]; then
git config branch.$BRANCHNAME.merge refs/heads/master
MERGE=refs/heads/master
fi
# set push on origin to be gerrit friendly and use the correct branch
PUSH=${MERGE#refs/heads/}
git config remote.origin.push HEAD:refs/for/$PUSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment