Main Content

addRemote

Add new remote to Git repository

Since R2025a

    Description

    remoteDetails = addRemote(repo,URL) adds a new remote specified by URL to the Git™ repository repo.

    example

    remoteDetails = addRemote(repo,URL,Name=Value) specifies additional options as one or more name-value arguments. Use this syntax to add a remote name and a different push URL.

    example

    Examples

    collapse all

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Add a new remote.

    remoteDetails = addRemote(repo,"https://github.com/my/remote/repo")
    
    remoteDetails = 
    
      GitRemote with properties:
    
           Name: "origin"
            URL: "https://github.com/my/remote/repo"
        PushURL: "https://github.com/my/remote/repo"

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Add a named remote.

    remoteDetails = addRemote(repo,"https://github.com/my/remote/repo",...
        Name="fork")
    remoteDetails = 
    
      GitRemote with properties:
    
           Name: "fork"
            URL: "https://github.com/my/remote/repo"
        PushURL: "https://github.com/my/remote/repo"

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Add a remote with a different push URL.

    remoteDetails = addRemote(repo,"https://github.com/my/internal/url",...
        PushURL="https://github.com/my/public/url")
    remoteDetails = 
    
      GitRemote with properties:
    
           Name: "origin"
            URL: "https://github.com/my/internal/url"
        PushURL: "https://github.com/my/public/url"

    Input Arguments

    collapse all

    Git repository, specified as a matlab.git.GitRepository object.

    URL of the remote repository, specified as a string scalar or a character vector.

    Example: "https://github.com/my/repo"

    Data Types: char | string

    Name-Value Arguments

    collapse all

    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: remote=addRemote(repo,"https://github.com/my/repo",Name="fork");

    Name of the remote, specified as a string scalar or a character vector.

    Example: "fork",'origin'

    Data Types: char | string

    URL used to upload the local repository to the remote repository, specified as a character vector or string scalar.

    Data Types: char | string

    Output Arguments

    collapse all

    Details of the remote, returned as a matlab.git.GitRemote object.

    Version History

    Introduced in R2025a