gitclone - Clone Git repository - MATLAB (original) (raw)
Clone Git repository
Since R2023b
Syntax
Description
[repo](#mw%5F52o92940f3601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitclone([repositoryURL](#mw%5F52o92940f3601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5Fe42db8e7-a6e4-4f00-bc1c-a193dccaab32))
clones the Git™ remote repository repositoryURL
into the current folder and returns a matlab.git.GitRepository
object.
[repo](#mw%5F52o92940f3601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitclone([repositoryURL](#mw%5F52o92940f3601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5Fe42db8e7-a6e4-4f00-bc1c-a193dccaab32),[folder](#mw%5Fce19ae18-fa5b-413b-a9c0-384bd2f925cb))
clones the Git remote repository repositoryURL
into the specified folderfolder
and returns a matlab.git.GitRepository
object.
[repo](#mw%5F52o92940f3601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitclone(___,[Name=Value](#namevaluepairarguments))
specifies additional options as one or more name-value arguments.
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, seeManage 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.
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 asName1=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 logical1
(true
) or 0
(false
).
Data Types: logical
Output Arguments
Version History
Introduced in R2023b