gitclone
Syntax
Description
clones the Git™ remote repository repo
= gitclone(repositoryURL
)repositoryURL
into the current folder
and returns a matlab.git.GitRepository
object.
clones the Git remote repository repo
= gitclone(repositoryURL
,folder
)repositoryURL
into the specified folder
folder
and returns a matlab.git.GitRepository
object.
specifies additional options as one or more name-value arguments.repo
= gitclone(___,Name=Value
)
Examples
Clone Git Repository in Current Folder
Clone a repository in the current folder.
repo = gitclone("https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests")
repo = GitRepository with properties: WorkingFolder: "C:\myWorkSpace\newrepo" GitFolder: "C:\myWorkSpace\newrepo\.git" CurrentBranch: [1×1 GitBranch] (main) LastCommit: [1×1 GitCommit] (3fa5e35) ModifiedFiles: [0×1 string] UntrackedFiles: [0×1 string] IsBare: 0 IsShallow: 0 IsDetached: 0 IsWorktree: 0
To clone a passphrase-protected repository, specify your login information for the Git repository account, for example GitHub®. For more information, see Clone Passphrase-Protected Repository.
Clone Passphrase-Protected Repository
Clone a passphrase-protected repository hosted on GitHub.
url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests"; secrets = loadenv("github.env"); repo = gitclone(url,Username=secrets("GITHUB_USER"),Token=secrets("GITHUB_TOKEN"))
repo = GitRepository with properties: WorkingFolder: "C:\myWorkSpace\newrepo" GitFolder: "C:\myWorkSpace\newrepo\.git" CurrentBranch: [1×1 GitBranch] (main) LastCommit: [1×1 GitCommit] (3fa5e35) ModifiedFiles: [0×1 string] UntrackedFiles: [0×1 string] IsBare: 0 IsShallow: 0 IsDetached: 0 IsWorktree: 0
To prevent frequent login prompts when you interact with your remote repository using HTTPS, configure a Git credential manager to remember credentials. For more information, see Manage Git Credentials.
Clone Git Repository in Specified Folder
Clone a repository in the specified folder.
mkdir("newrepo"); url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests"; repo = gitclone(url,"newrepo\")
repo = GitRepository with properties: WorkingFolder: "C:\myWorkSpace\newrepo" GitFolder: "C:\myWorkSpace\newrepo\.git" CurrentBranch: [1×1 GitBranch] (main) LastCommit: [1×1 GitCommit] (3fa5e35) ModifiedFiles: [0×1 string] UntrackedFiles: [0×1 string] IsBare: 0 IsShallow: 0 IsDetached: 0 IsWorktree: 0
Shallow Clone Git Repository
Clone only the most recent commit.
url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests";
repo = gitclone(url,Depth=1);
Verify that the clone is shallow.
repo.IsShallow
ans = logical 1
Input Arguments
repositoryURL
— URL of remote repository
string scalar
URL of the remote repository, specified as a string scalar.
folder
— Path of folder
character vector | string scalar
Path of the folder in which the function clones the repository, specified as a character vector or string scalar.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: gitclone(url,Username="myusername",Token="mypersonaltoken",Depth=10)
Username
— Username for Git repository account
character vector | string scalar
Username for the Git repository account, specified as a character vector or string scalar.
Data Types: char
| string
Token
— Personal access token for Git repository account
character vector | string scalar
Personal access token for the Git repository account, specified as a character vector or string scalar.
Data Types: char
| string
Depth
— Depth of shallow clone
0
(default) | non-negative integer
Depth of the shallow clone, specified as a non-negative integer.
If you do not specify the depth, gitclone
performs a full
clone. Otherwise, gitclone
clones only the number of commits
specified by Depth
.
Data Types: single
RecurseSubmodules
— Option to clone Git submodules recursively
true
or 1
(default) | false
or 0
Option to clone Git submodules recursively, specified as a numeric or logical
1
(true
) or 0
(false
).
Data Types: logical
Output Arguments
repo
— Git repository
matlab.git.GitRepository
object
Git repository, returned as a matlab.git.GitRepository
object.
Version History
Introduced in R2023b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)