I recently started working at Blue Box and we use GitHub Enterprise (GHE) for all of our apps. I had gotten in the habit of using hub to improve my git workflow and was curious if I could use hub
with GHE. I turned to the docs and sure enough, you can!
The docs tell you two ways of setting up hub
to use GHE:
By default, hub will only work with repositories that have remotes which point to github.com. GitHub Enterprise hosts need to be whitelisted to configure hub to treat such remotes same as github.com:
$ git config --global --add hub.host my.git.org
The default host for commands like init and clone is still github.com, but this can be affected with the GITHUB_HOST environment variable:
$ GITHUB_HOST=my.git.org git clone myproject
I want to use both github.com and GHE, so I decided to create a couple of shell functions to save my fingers from all of that extra typing.
Clone a repo (probably your fork of the master repo)
$ ghe clone <username>/<repo>
Setup the repo to use GHE by default
$ ghe-setup
NOTE: Be sure to alias hub as git ;)
# example with zsh
hub_path=$(which hub)
if (( $+commands[hub] ))
then
alias git=$hub_path
fi
Set up the master branch to track the master repo that everyone will send pull requests to
$ git remote add <remote-name> <username>/<repo-name>
Fetch the remote
$ git fetch <remote-name>
Set up the main repo master branch as the upstream for local master
$ git branch -u <remote-name>/master
Code. Commit. Push.
Submit a pull request
$ git pull-request -b <remote-name>:master
There's so much more you can do with hub
, so be sure to check out the docs:
$ man hub