Skip to content

Instantly share code, notes, and snippets.

@fadookie
Last active June 27, 2019 21:26
Show Gist options
  • Save fadookie/a69bcbcb8625d8a914ac14a01ef221cb to your computer and use it in GitHub Desktop.
Save fadookie/a69bcbcb8625d8a914ac14a01ef221cb to your computer and use it in GitHub Desktop.
Hub git aliases
[alias]
browse-tree = !cd -- ${GIT_PREFIX:-.} && hub browse -- tree/"${1-$(git rev-parse --abbrev-ref HEAD)}" # Use argument, or default to HEAD
browse-commit = !cd -- ${GIT_PREFIX:-.} && hub browse -- commit/"${1-$(git rev-parse --short HEAD)}" # Use argument, or default to HEAD
browse-file = !cd -- ${GIT_PREFIX:-.} && hub browse -- blob/"$(git rev-parse --short HEAD)"/$(git ls-files --full-name "$1")
browse-pr = !hub pr list -h "$(git rev-parse --abbrev-ref HEAD)" -f '%U%n' | xargs open

Hub git aliases

These are aliases for the hub git wrapper tool.

See mislav/hub#1904

Install

Copy these into your ~/.gitconfig file.

Usage

#Open HEAD branch:
git browse-tree

#Open specific branch/tree:
git browse-tree some_branch

#Open HEAD commit:
git browse-commit

#Open specific commit:
git browse-commit 1c2306d92ab0ae621991668879f85c750c576697

#Open file inside HEAD tree - should work within subdirectories also:
git browse-file some.file

# Open any PRs from current branch on same repo
git browse-pr

Note for non-macOS users

For browse-pr, on non-mac platforms you can just remove |xargs open or replace open with whatever command you use to open a web browser to a specific URL.

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