Skip to content

Instantly share code, notes, and snippets.



Last active Nov 14, 2017
What would you like to do?
Shell functions to aid in using hub(1) with GitHub Enterprise.

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 Enterprise hosts need to be whitelisted to configure hub to treat such remotes same as

$ git config --global --add

The default host for commands like init and clone is still, but this can be affected with the GITHUB_HOST environment variable:

$ git clone myproject 

I want to use both 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] ))
  alias git=$hub_path

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
# Allows you to use hub(1) with your GitHub Enterprise
# account without setting it globally in your ~/.gitconfig.
# Example: `ghe clone username/repo`
function ghe() {
# Setup an existing repo to use GitHub Enterprie exclusively
function ghe-setup() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.