Main Content

Share Git Repository to Remote

This example shows how to link a local Git™ repository to a remote repository.

Open the example to download the supporting files under Git source control.

You made changes to files in your local Git™ repository and are ready to share your work with others. If you have not yet initialized a Git repository, see Create Local Git Repository in MATLAB.

If you want to share a repository to GitHub, see Share to GitHub. To share to a remote hosted on any other platform, see Add Remote.

Add Remote

To link your local Git repository to a remote repository, follow these steps.

  1. You must first create a remote repository on the platform that will host your repository, such as on GitLab® or BitBucket. Then, create a personal access token. For instructions on how to create personal access tokens for GitLab, see Personal access tokens.

  2. Add a remote URL to your local repository. In the Files or Project panel, right-click the white space and select Source Control > Add Remote. If you are using MATLAB® Projects, you can also add a remote by clicking Add Remote in the Project toolstrip. Alternatively, in the Source Control panel, click the More source control options button More source control options icon and select Add Remote. If the Source Control icon Source Control side panel icon. is not in a sidebar, click the Open more panels button Open more panels icon and select the Source Control panel.

  3. Specify the name and the URL of the remote you created. Then, click Add. Add Remote dialog box. Name and URL fields and Add and Cancel buttons below.

  4. Push your changes to the remote repository. In the Files or Project panel, right-click the white space and select Source Control > Push. If an authentication dialog box appears, enter the login information for your Git repository account. Alternatively, in the Source Control panel, click the More source control options button More source control options icon and select Push.

Share to GitHub

To share your local Git repository to GitHub, follow these steps.

  1. You must first have a GitHub account and a personal access token. For instructions on how to create personal access tokens for GitHub, see Creating a personal access token.

  2. In the Files or Project panel, right-click the white space and select Source Control > Share to GitHub. Alternatively, in the Source Control panel, click the More source control options button More source control options icon and select Share to GitHub.

  3. Specify the name of the remote repository name. Then, click Create. If an authentication dialog box appears, enter the username and personal access token for your GitHub repository account.

Create GitHub Repository dialog box. Repository name field and a checkbox to make the repository private, and Create and Cancel buttons below.

By default, MATLAB® creates a private remote repository on GitHub and pushes your changes. To make the repository public, clear the Make the GitHub repository private checkbox before you click Create.

Tips:

  • To link more than one remote to your repository, use the Branch Manager. For more information, see Add Git Remote.

  • To find the URL address for your remote repository, in the Files or Project panels, right-click and select Source Control > View Details. Alternatively, you can open the remote URL in a Web browser from the Branch Manager. For more information, see Manage Git Remote Branches and Repositories Locally.

See Also

Tools

Topics