Gemfile simply tells Bundler which gems your project needs, which versions of those gems need, and where to get them. Your question is related to the third point. In general, there are four possible sources of gems:
1. Install from mirror source
This is the most straightforward. If a gem is specified in this way, Bundler will look for the gem in the source at the beginning of the file:
gem 'rails' # this gem will be installed from https://rubygems.org
2. Install from the Git repository
By specifying Git parameters in the gem method (Gemfile is actually a Ruby code file), Bundler can pull code from a specified remote repository, such as:
# nokogiri will be installed from git://github.com/tenderlove/nokogiri.git
gem 'nokogiri', :git => 'git://github.com/tenderlove/nokogiri.git'
3. Install from GitHub
The second method above is for all valid Git repositories (not just GitHub, but your own repository on a Git server), but if the repository you need comes from GitHub, you can use the more convenient GitHub parameter to achieve this:
gem 'nokogiri', :github => 'tenderlove/nokogiri'
As you can see, as long as you specify the author/repo_name form, Bundler can automatically retrieve the gem you need from GitHub. Note: Both the second and third methods also specify the branch you want with the branch parameter, such as:
gem 'refinerycms', github: 'refinery/refinerycms', branch: 'master'
4. Install from the file system
If you have a gem that is already in the project directory (it could be anywhere), you can specify the desired gem location in the filesystem using the path parameter, such as:
gem "rails", :path => "vendor/rails"
The Bundler finds and installs the gem based on the path specified by the Bundler.
One last word
Finally, I’d like to note that gems like this usually come from the project directory, mostly because the project uses frameworks that provide extension mechanisms, such as Spree and Refinery, which generate extensions or sub-engines in the form of gems in the vendor or lib directory. Then specify it from Gemfile, such as an instance of one of my projects:
gem 'refinerycms-factories', :path => 'vendor/extensions'
RefineryCMS-Factories is a subengine I generated using the Refinery Generator, which is placed by default in the Verdor /extensions directory.
Another common scenario is that you are using a gem that may no longer be maintained, and because of the major changes to the source code, you simply download the gem source code to your local project directory, modify it directly, and then install it via PATH.
For more information about Gemfiile, please click on the Bundler homepage Gemfile manual page