Main Content

push

Publish local changes to remote Git repository

Since R2023b

    Description

    push(repo) publishes changes in the current branch of the local Git™ repository repo to the remote repository. Use this syntax to push branches that already have configured remotes, such as the main branch.

    example

    push(repo,Name=Value) specifies additional options as one or more name-value arguments.

    example

    Examples

    collapse all

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Switch to the newFeature branch that you want to push to the remote repository.

    switchBranch(repo,"newFeature");

    Push local changes on the current branch to the remote repository.

    push(repo);

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Switch to the newFeature branch that you want to push to the remote repository.

    switchBranch(repo,"newFeature");

    Push local changes on the current branch to the remote repository.

    push(repo);

    To push the changes from a local branch that does not have a configured remote, specify the Remote argument.

    The function creates an upstream branch named origin/newFeature in the remote repository.

    push(repo,Remote="origin");

    To push the changes on the current branch to a remote branch that has a different name, specify the RemoteBranch argument.

    The function creates an upstream branch named origin/betterName.

    push(repo,Remote="origin",RemoteBranch="betterName");

    To push the changes to a passphrase-protected remote repository, specify the Username and Token arguments.

    secrets = loadenv("github.env");
    push(repo,Username=secrets("GITHUB_USER"),Token=secrets("GITHUB_TOKEN"),Remote="origin",RemoteBranch="betterName");

    Input Arguments

    collapse all

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

    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: push(repo,Remote="origin",RemoteBranch="myNewTask")

    Username for the Git repository account, specified as a character vector or string scalar.

    Data Types: char | string

    Personal access token for the Git repository account, specified as a character vector or string scalar.

    Data Types: char | string

    Name of the remote to which the function publishes data, specified as a character vector or string scalar.

    Data Types: char | string

    Name of the remote branch to which the function publishes data, specified as a character vector or string scalar. If you do not specify this input, the function uses the local branch name to create the remote branch.

    Data Types: char | string

    Version History

    Introduced in R2023b