How do I access a private github repo from heroku? How do I access a private github repo from heroku? heroku heroku

How do I access a private github repo from heroku?


This worked for me:

  1. Generate a Github Access Token
  2. In requirements.txt list private module as follows:

    git+https://your_user_name:your_git_token@github.com/your_company/your_module.git


You need to use username/password in the Gemfile, or vendor the dependency. You can also use Gemfury (assuming it's a gem):


Heroku only supports HTTP(S) Basic authentication with Git out of the box. That's unfortunate as it means you'd need to add your credentials as part of the installation URL and commit that as plain text in your list of dependencies. For your app to support SSH keys instead, do the following:

  1. Create a new SSH key which will be used by Heroku to access the GitHub repository. Choose a distinct name, e.g. id_rsa_heroku.
  2. Add the public part of the key to your GitHub account (link to settings).
  3. Use the heroku-buildpack-ssh-key: heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ssh-key.git -i 1
  4. Set the private part of the key as an environment variable for your Heroku app: heroku config:set BUILDPACK_SSH_KEY=$(cat ~/.ssh/id_rsa_heroku)

From this moment, Heroku should be able to access and download code from any private repositories you have access to.