Skip to content

Instantly share code, notes, and snippets.

@n8io
Last active August 29, 2015 14:19
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 n8io/6bd043157bb8322e27c8 to your computer and use it in GitHub Desktop.
Save n8io/6bd043157bb8322e27c8 to your computer and use it in GitHub Desktop.
A bookmarklet for easily copying the git commands to checkout a given pull request in Bitbucket and Stash.

Alt text #Why? Atlassian doesn't currently provide an easy way to checkout a pull request from their web interface. This bridges that gap.

#Compatibilites This bookmarklet works in Atlassian's BitBucket and Stash products as of 4/15/2015.

#How to bookmarklet

  1. Create a bookmark
  2. Paste the code in as the url.
  3. Navigate to a Pull Request page
  4. Click on your bookmark

You should see a textbox like the screenshot like above.

javascript:function() {
var input;
var branch;
var anchorEl;
if(!window.jQuery){
return;
}
branch = jQuery('.aui-iconfont-devtools-branch-small:eq(0)').next().attr('title') || jQuery('.aui-iconfont-devtools-branch-small:eq(0)').next().text();
anchorEl = jQuery('.pull-request-title').length ? jQuery('.pull-request-title') : jQuery('.pull-request-branches').next();
if(jQuery('.checkout-command').length === 0){
input = '<input type="text" class="checkout-command" readonly="readonly" style="width: 100%; margin-top: 15px;">';
jQuery(input).insertBefore(anchorEl);
}
jQuery('.checkout-command').val('git fetch && git checkout ' + branch);
jQuery('.checkout-command').select().focus();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment