DEV Community

Discussion on: Open the GitHub project page of a repo from Terminal

Collapse
 
math2001 profile image
Mathieu PATUREL

Personally, I prefer this command to be associated with the hub alias, so I can just run:

git hub
Enter fullscreen mode Exit fullscreen mode

And since the folder name is really often the same as the repository name, here's my solution:

git config --global alias.hub '!f () { local REPO;local URL;[[ -f .githubrepo ]] && REPO="$(head -n 1 .githubrepo)" || REPO="${PWD##*/}";URL="https://github.com/<your username>/$REPO";if [[ "$1" == i ]];then URL="$URL/issues";elif [[ "$1" == s ]];then URL="$URL/settings";elif [[ "$1" == p ]];then URL="$URL/pulls";elif [[ "$1" == w ]];then URL="$URL/wiki";elif [[ "$1" == b ]];then URL="$URL/branches";elif [[ "$1" == r ]];then URL="$URL/releases";fi;echo "Opening $URL...";start "$URL";};f'
Enter fullscreen mode Exit fullscreen mode

Make sure you change <your username> to your username.

Now you can run

$ git hub -> opens the repo depending on the folder's name
$ git hub i -> opens issues/ 
$ git hub p -> opens pulls/
$ git hub s -> opens settings/
$ git hub w -> opens wiki/
$ git hub b -> opens branches/
$ git hub r -> opens releases/
$ git hub whatever -> opens whatever/
Enter fullscreen mode Exit fullscreen mode

If the name of the folder doesn't correspond to the name of the repository, you can add a .githubrepo file and set its content to the name of it, and it'll use this instead.

Hopefully it'll save some people a bit of time