Method: Git::Base.clone
- Defined in:
- lib/git/base.rb
permalink .clone(repository_url, directory, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory
Examples:
Clone into the default directory ruby-git
Clone into the default directory ruby-git
git = Git.clone('https://github.com/ruby-git/ruby-git.git')
Clone and then checkout the development
branch
Clone and then checkout the development
branch
git = Git.clone('https://github.com/ruby-git/ruby-git.git', branch: 'development')
Clone into a different directory my-ruby-git
Clone into a different directory my-ruby-git
git = Git.clone('https://github.com/ruby-git/ruby-git.git', 'my-ruby-git')
# or:
git = Git.clone('https://github.com/ruby-git/ruby-git.git', path: 'my-ruby-git')
Create a bare repository in the directory ruby-git.git
Create a bare repository in the directory ruby-git.git
git = Git.clone('https://github.com/ruby-git/ruby-git.git', bare: true)
Clone a repository and set a single config option
Clone a repository and set a single config option
git = Git.clone(
'https://github.com/ruby-git/ruby-git.git',
config: 'submodule.recurse=true'
)
Clone a repository and set multiple config options
Clone a repository and set multiple config options
git = Git.clone(
'https://github.com/ruby-git/ruby-git.git',
config: ['user.name=John Doe', 'user.email=john@doe.com']
)
Parameters:
-
repository_url
(URI, Pathname)
—
The (possibly remote) repository url to clone from. See GIT URLS for more information.
-
directory
(Pathname, nil)
—
The directory to clone into
If
directory
is a relative directory it is relative to thepath
option if given. Ifpath
is not given,directory
is relative to the current working directory.If
nil
,directory
will be set to the basename of the last component of the path from therepository_url
. For example, for the URL:https://github.com/org/repo.git
,directory
will be set torepo
.If the last component of the path is
.git
, the next-to-last component of the path is used. For example, for the URL/Users/me/foo/.git
,directory
will be set tofoo
. -
options
(Hash)
(defaults to: {})
—
The options for this command (see list of valid options below)
Options Hash (options):
-
:bare
(Boolean)
—
Make a bare Git repository. See what is a bare repository?.
-
:branch
(String)
—
The name of a branch or tag to checkout instead of the default branch.
-
:config
(Array, String)
—
A list of configuration options to set on the newly created repository.
-
:depth
(Integer)
—
Create a shallow clone with a history truncated to the specified number of commits.
-
:filter
(String)
—
Request that the server send a partial clone according to the given filter
-
:log
(Logger)
—
A logger to use for Git operations. Git commands are logged at the
:info
level. Additional logging is done at the:debug
level. -
:mirror
(Boolean)
—
Set up a mirror of the source repository.
-
:origin
(String)
—
Use the value instead
origin
to track the upstream repository. -
:path
(Pathname)
—
The directory to clone into. May be used as an alternative to the
directory
parameter. If specified, thepath
option is used instead of thedirectory
parameter. -
:recursive
(Boolean)
—
After the clone is created, initialize all submodules within, using their default settings.
Returns:
-
(Git::Base)
—
an object that can execute git commands in the context of the cloned local working copy or cloned repository.
See Also:
23 24 25 26 27 |
# File 'lib/git/base.rb', line 23 def self.clone(repository_url, directory, options = {}) new_options = Git::Lib.new(nil, options[:log]).clone(repository_url, directory, options) normalize_paths(new_options, bare: options[:bare] || options[:mirror]) new(new_options) end |