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 a repository in the current folder.
repo = gitclone("https://github.com/domain/examplerepo")
repo =
GitRepository with properties:
WorkingFolder: "C:\myWorkSpace\examplerepo"
GitFolder: "C:\myWorkSpace\examplerepo\.git"
CurrentBranch: [1×1 GitBranch] (main)
LastCommit: [1×1 GitCommit] (3fa5e35)
Remotes: [2×1 GitRemote] (origin trunk)
ModifiedFiles: [0×1 string]
UntrackedFiles: [0×1 string]
IsBare: 0
IsShallow: 0
IsDetached: 0
IsWorktree: 0To clone a private repository, specify your login information for the Git repository account, for example GitHub®. For more information, see Clone Token-Protected Private Repository.
Clone a private repository hosted on GitHub.
url = "https://github.com/domain/examplerepo"; repo = gitclone(url,Username="user",Token=getSecret("GITHUB_TOKEN"))
repo =
GitRepository with properties:
WorkingFolder: "C:\myWorkSpace\examplerepo"
GitFolder: "C:\myWorkSpace\examplerepo\.git"
CurrentBranch: [1×1 GitBranch] (main)
LastCommit: [1×1 GitCommit] (3fa5e35)
Remotes: [2×1 GitRemote] (origin trunk)
ModifiedFiles: [0×1 string]
UntrackedFiles: [0×1 string]
IsBare: 0
IsShallow: 0
IsDetached: 0
IsWorktree: 0If you are cloning a repository using SSH keys, see Clone Repository Using SSH Keys instead.
Clone a repository in the specified folder.
mkdir("newrepo"); url = "https://github.com/domain/examplerepo"; 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)
Remotes: [2×1 GitRemote] (origin trunk)
ModifiedFiles: [0×1 string]
UntrackedFiles: [0×1 string]
IsBare: 0
IsShallow: 0
IsDetached: 0
IsWorktree: 0Clone only the most recent commit.
url = "https://github.com/domain/examplerepo";
repo = gitclone(url,Depth=1);
Verify that the clone is shallow.
repo.IsShallow
ans = logical 1
You can clone a repository using SSH.
You must first configure MATLAB® to use Git SSH authentication. For more information, see Configure MATLAB to Use Git SSH Authentication.
Clone a repository hosted on GitHub using SSH keys.
sshUrl = "git@github.com:user/examplerepo.git.";
gitclone(sshUrl);If the SSH key is passphrase-protected, specify the
SSHKeyPassphrase argument.
gitclone(sshUrl,SSHUsername="user",SSHKeyPassphrase=getSecret("SSH_PASS"));
Clone only the FeatureB branch from the Git repository.
url = "https://github.com/domain/examplerepo"; gitclone(url,Branch="FeatureB",SingleBranch=true);
Input Arguments
HTTPS or SSH URL of the remote repository, specified as a 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 for the Git repository account, specified as a character vector or string scalar.
SSH and Token based authentication are not compatible. Specify either
SSHKeyPassphrase and SSHUsername, or
Username and Token.
Data Types: char | string
Personal access token for the Git repository account, specified as a character vector or string scalar.
SSH and Token based authentication are not compatible. Specify either
SSHKeyPassphrase and SSHUsername, or
Username and Token.
Data Types: char | string
Since R2026a
Username for the Git repository account associate with the SSH key, specified as a character vector or string scalar.
SSH and Token based authentication are not compatible. Specify either
SSHKeyPassphrase and SSHUsername, or
Username and Token.
Data Types: char | string
Since R2026a
Passphrase of the used SSH key for the Git repository account, specified as a character vector or string scalar.
SSH and Token based authentication are not compatible. Specify either
SSHKeyPassphrase and SSHUsername, or
Username and Token.
Data Types: char | string
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
Option to clone Git submodules recursively, specified as a numeric or logical
1 (true) or 0
(false).
Data Types: logical
Since R2026a
Name of the branch to switch to after clone, specified as a string scalar or a character vector.
If you do not specify the branch name, gitclone clones the
default branch, usually called "main".
Example: "BugIssue1032",
'FeatureB'
Data Types: char | string
Since R2026a
Option to clone a single Git branch from the repository, specified as a numeric or logical
1 (true) or 0
(false).
Data Types: logical
Output Arguments
Git repository, returned as a matlab.git.GitRepository object.
Version History
Introduced in R2023bYou can specify the SSH passphrase when you programmatically interact with a Git repository using the gitclone,
fetch, push, and pull
functions.
sshUrl = "git@github.com:user/examplerepo.git."; gitclone(sshUrl,SSHUsername="user",SSHKeyPassphrase=getSecret("SSH_PASS"));
You can clone and switch a branch in a single command using the
Branch argument.
url = "https://github.com/domain/examplerepo"; gitclone(url,Branch="FeatureB");
You can clone a single branch from the repository using the
SingleBranch argument.
url = "https://github.com/domain/examplerepo"; gitclone(url,Branch="FeatureB",SingleBranch=true);
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)