Force bundle install to use https:// instead of git:// for GitHub-based gems

I am trying to build a rails project and because the host I am working on doesn’t have access to the Internet for the the git:// protocol (port 9418) I get errors like

Fetching git://
fatal: unable to connect to[0:]: errno=Connection refused

when running bundle install.

  • rake release fail (using gem bundler)
  • Conflicts in Gemfile.lock while rebasing
  • Run bundle install inside a Ruby script?
  • rails3 + bundler + git problem
  • Should Gemfile.lock be included in .gitignore?
  • How to deploy to Heroku with a different Gemfile / BUNDLE_GEMFILE
  • The relevant line in the GemFile doesn’t specify git:// as a protocol, it just points to GitHub as the source for the gem

    gem 'jasmine', :github => 'pivotal/jasmine-gem'

    What do I have to do to make bundler to use https:// rather than git:// for pulling gems from GitHub?


    Is there a way other than editing every affected line in the GemFile? I’d prefer to avoid any merging issues down the line if the project’s GemFile is updated.

  • Composer: use specific commit of your own fork of a third party library
  • Jenkins Build Using Git with Deploy Key
  • Git: copying a local repo to another folder
  • Call GitHub API with Travis to build Tag
  • Netbeans with GitHub commit only selected files
  • Manage different codebases using single git repository instead of submodules
  • 6 Solutions collect form web for “Force bundle install to use https:// instead of git:// for GitHub-based gems”

    Git provides URL rewriting functionality using the url..insteadOf configuration option.

    So to make all connections to use https:// rather than git://

    git config --global url."".insteadOf git://

    The --global switch sets the config option for all git operations by the current user, so there are times where it may be too intrusive. But it does avoid changing the git config in the current project.

    You can do:

    gem 'jasmine', git: ''

    Use bundle config github.https true

    If you want this just for all the gems in one Gemfile you can add these lines at the top of the file:

    git_source(:github) do |repo_name|
      repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")

    Alternatively you can use bundle config github.https true. But this affects only your current environment.

    This won’t be necessary anymore with Bundler 2.0.

    if you’re deploying to heroku, you can just add BUNDLE_GITHUB__HTTPS (note the double underscore) as an environment variable and set it to true (in your heroku app’s dashboard under the Settings tab in the Config Vars section). this will switch the protocol from git:// to https:// for all such requests.

    You should be able to put a complete Git URL in your Gemfile. For example:

    gem 'jasmine', :git => '' 
    Git Baby is a git and github fan, let's start git clone.