How can I specify a gem to pull from a private github repository?

The best way I’ve found to deploy a gem pulled from a private repo is to use GitHub’s OAuth access. To do so:

  1. Create a GitHub user with access to the repo in question (best for teams – if you’re okay exposing your personal access tokens, you can simply use your own account).

  2. Create an GitHub OAuth token for the user. It’s dead simple to do this over the GitHub API just using curl; see the OAuth API for more.

  3. Add the token to the git url in your Gemfile. Example:

gem 'mygem', git: 'https://xxx123abc:[email protected]/user_or_team/mygem.git'

I’m currently using this method on Heroku and it works great. The beauty is that you don’t have to expose your own personal information, and you can revoke or regenerate the token at any point if something is compromised.

Leave a Comment