ruby/ruby · error · DeprecatedError

You can no longer specify a git source by itself. Instead,

Error message

You can no longer specify a git source by itself. Instead, 
either use the :git option on a gem, or specify the gems that 
bundler should find in the git source by passing a block to 
the git method, like: 

  git 'git://github.com/rails/rails.git' do
    gem 'rails'
  end

What it means

In Bundler 1.x, `git "git://..."` alone declared a git source and later gems could attach to it implicitly. Bundler 2 removed implicit attachment, so calling `git` without a block raises DeprecatedError with migration instructions: either pass :git per gem or enumerate the gems in a block. This is a hard migration error, not a warning.

Source

Thrown at lib/bundler/dsl.rb:184

        "root_path" => gemfile_root
      )

      source_options["global"] = true unless block_given?

      source = @sources.add_path_source(source_options)
      with_source(source, &blk)
    end

    def git(uri, options = {}, &blk)
      unless block_given?
        msg = "You can no longer specify a git source by itself. Instead, \n" \
              "either use the :git option on a gem, or specify the gems that \n" \
              "bundler should find in the git source by passing a block to \n" \
              "the git method, like: \n\n" \
              "  git 'git://github.com/rails/rails.git' do\n" \
              "    gem 'rails'\n" \
              "  end"
        raise DeprecatedError, msg
      end

      with_source(@sources.add_git_source(normalize_hash(options).merge("uri" => uri)), &blk)
    end

    def github(repo, options = {})
      raise InvalidArgumentError, "GitHub sources require a block" unless block_given?
      github_uri  = @git_sources["github"].call(repo)
      git_options = normalize_hash(options).merge("uri" => github_uri)
      git_source  = @sources.add_git_source(git_options)
      with_source(git_source) { yield }
    end

    SUPPORTED_OVERRIDE_FIELDS = [:version, :required_ruby_version, :required_rubygems_version].freeze
    SUPPORTED_OVERRIDE_SYMBOL_OPERATIONS = [:ignore_upper].freeze

    def override(target, **operations)
      validate_override_target!(target)

View on GitHub (pinned to 0e5b888e1c)

Solutions

  1. Move the repo onto the gems that use it with a block: `git "https://github.com/rails/rails.git" do; gem "rails"; end`.
  2. Or attach per gem: `gem "rails", git: "https://github.com/rails/rails.git"`.
  3. For shared shorthands, define git_source(:github){...} and use `gem "rails", github: "rails/rails"`.
  4. If you cannot edit the Gemfile yet, run with the legacy Bundler 1.x version (`gem install bundler -v '~> 1.17'` then `bundle _1.17.3_ install`).

Example fix

# before (Bundler 1.x style)
git "git://github.com/rails/rails.git"
gem "rails"

# after (Bundler 2+)
git "https://github.com/rails/rails.git" do
  gem "rails"
end
Defensive patterns

Strategy: validation

Validate before calling

# Lint legacy Gemfiles before running Bundler 2
content = File.read("Gemfile")
if content =~ /^\s*git\s+["'][^"']+["']\s*$/ && !content.match?(/^\s*git\s+["'][^"']+["']\s+do/)
  abort "Bare `git \"url\"` lines must be migrated to block form or `gem ..., git:`"
end

Prevention

When it happens

Trigger: A Gemfile written for Bundler 1.x containing a bare `git "git://github.com/rails/rails.git"` line, evaluated under Bundler 2+. Often surfaces after upgrading Bundler or when an old project is opened with a newer toolchain.

Common situations: Upgrading from Bundler 1.17 to 2.x; legacy Gemfiles in long-lived internal projects; tutorial/documentation examples predating Bundler 2.

Related errors


AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21). Data as JSON: /api/errors/2bcedaca5a49aaf1. Report an issue: GitHub.