12

I have tryed different approaches to use a Github private repository reference in a Rails application Gemfile.

1) Gemfile:
gem 'my_gem', :git => "https://#{github_user}:#{github_pw}@github.com/me/my_gem.git"

Result from 'git push heroku':

Fetching https://user:pw@github.com/me/my_gem.git
error: The requested URL returned error: 401 while accessing https://user:pw@github.com/me/my_gem.git/info/refs
Git error: command `git clone 'https://user:pw@github.com/me/my_gem.git' "/tmp/build_2wxmqutch8gy7/vendor/bundle/jruby/1.9/cache/bundler/git/my_gem-929bddeee3dd4a564c2689e189190073df01431e" --bare --no-hardlinks` in directory /tmp/build_2wxmqutch8gy7 has failed.
Dependencies installed

Then I found this article https://help.github.com/articles/creating-an-oauth-token-for-command-line-use and created an OAuth token.

2) Gemfile:
gem 'my_gem', :git => "https://#{github_oauth_token}@github.com/me/my_gem.git"

Result from 'git push heroku':

Fetching https://0123456789abcdef0123456789abcdef01234567@github.com/me/my_gem.git
Password:

Heroku stall and prompt for a password.

On my local machine both:

git clone https://user:pw@github.com/me/my_gem.git

and

git clone https://0123456789abcdef0123456789abcdef01234567@github.com/me/my_gem.git

works perfekt!

Local:

# git --version
git version 1.7.9.5

Heroku:

# heroku run git --version
git version 1.7.0
Jacob
  • 1,642
  • 2
  • 15
  • 27

2 Answers2

6

Heroku runs an older Git version, which unfortunately doesn't fully support the auth part of the URLs.

You can work around this by adding the dummy password supplied by GitHub. So instead of using:

https://#{github_oauth_token}@github.com/me/my_gem.git

Use:

https://#{github_oauth_token}:x-oauth-basic@github.com/me/my_gem.git
bergie
  • 930
  • 7
  • 8
  • Is there a way to do this for accessing a private repo owned by a github organization? I'm trying to get a private repo pulled in by bower via bower.json. – chandlervdw Oct 17 '13 at 15:32
  • This should work for both personal and organization repositories, as long as you have the permissions to access them with the account your OAuth token is for – bergie Dec 01 '13 at 04:56
2

Heroku's git (version 1.7) doesn't support using e-mail as username for Github's repositories.

You must use your Github username.

Also, Heroku's git doesn't support using an oauth token.

Hopefully Heroku will upgrade their git soon, so they can continue making my life easier :-)

Jacob
  • 1,642
  • 2
  • 15
  • 27