Skip to content

Instantly share code, notes, and snippets.

@maartenJacobs
Created February 17, 2012 16:16
Show Gist options
  • Save maartenJacobs/1854168 to your computer and use it in GitHub Desktop.
Save maartenJacobs/1854168 to your computer and use it in GitHub Desktop.
Hop-update branches
#!/bin/bash
end_branch=$1
# Get currently active branch
active_branch=$(g branch | ack '\* ([A-Za-z0-9]+)' | cut -d' ' -f 2)
# Stash current changes for rebase pull
stash_result=$(git stash)
# Update current branch
git pull --rebase origin $active_branch
git push origin $active_branch
# Make the hop
# TODO: replace origin with the remove ref name.
git checkout $end_branch
git pull --rebase origin $end_branch
git pull --rebase origin $active_branch
git push origin $end_branch
# Apply changes if a stash was applied
if [[ $stash_result == 'No local changes to save' ]]; then
git stash pop
fi
echo "Pulled down changes into endbranch $endbranch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment