Skip to content

Instantly share code, notes, and snippets.

@jkulak
Last active May 24, 2023 11:34
Show Gist options
  • Save jkulak/f75d3f9142871fcfcbf47823e7c51f72 to your computer and use it in GitHub Desktop.
Save jkulak/f75d3f9142871fcfcbf47823e7c51f72 to your computer and use it in GitHub Desktop.
Git alias to open GitHub page for current repository and current branch
# place it for example in your `~/.gitconfig` file
# Usage:
# type `git openbranch` in a directory with a GitHub repository
[alias]
openbranch = "!f() { \
branch_name=$(git symbolic-ref --short HEAD); \
origin_url=$(git config --get remote.origin.url); \
if [[ \"$origin_url\" == git@github.com:* ]]; then \
repo_url=\"https://github.com/${origin_url:15}\"; \
else \
repo_url=\"$origin_url\"; \
fi; \
repo_url=${repo_url%.git}; \
branch_url=\"$repo_url/tree/$branch_name\"; \
open \"$branch_url\"; \
}; f"
@jkulak
Copy link
Author

jkulak commented May 24, 2023

Currently uses open to use a default system browser to open the constructed GitHub url.

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