Skip to content

Instantly share code, notes, and snippets.

@ianonavy
Created December 20, 2017 20:35
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 ianonavy/1bad4a074645185ec7cdc017fb1e2d28 to your computer and use it in GitHub Desktop.
Save ianonavy/1bad4a074645185ec7cdc017fb1e2d28 to your computer and use it in GitHub Desktop.
git-update-branch

git-update-branch

Rebase-friendly alternative to the GitHub "Update Branch" button on the pull request page.

Rebases a remote origin branch onto the latest default branch. Right now, hard coded for "develop" even though most people use "master". Feel free to edit.

I personally use this when I have many remote branches to merge and want all of them to be up-to-date with the latest default branch after each rebase. Of course, if you don't prefer rebase as an updating strategy you can just use the "Update branch" button in the GitHub UI. This is a rebase-friendly alternative.

Installation

  • Create git-update-branch as an executable file, somewhere in your $PATH. I put mine in ~/bin.
  • Optional, but recommended: create git-update-branch-complete.bash and source inside your shell's profile (e.g. ~/.bash_profile).

License

Public domain

#!/bin/bash
usage() {
echo "Usage: git update-branch <remote branch>"
}
branch=$1
test -z $branch && usage && exit 1
echo "Fetching latest origin blobs"
git fetch
echo "Hard reset $branch to origin/$branch"
git update-ref refs/heads/$branch refs/remotes/origin/$branch
echo "Rebasing..."
git rebase origin/develop $branch
#!/bin/bash
_git_update_branch ()
{
# you can return anything here for the autocompletion for example all the branches
__gitcomp_nl "$(__git_refs)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment