Last active
May 24, 2023 11:34
-
-
Save jkulak/f75d3f9142871fcfcbf47823e7c51f72 to your computer and use it in GitHub Desktop.
Git alias to open GitHub page for current repository and current branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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\" == [email protected]:* ]]; 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently uses
open
to use a default system browser to open the constructed GitHub url.