Push and Fetch with Git

Use this workflow to work with a remote repository. With Git™, there is a two-step workflow: commit local changes, and then push to the remote repository. In MATLAB®, the only access to the remote repository is through the Push and Fetch menu options. All other actions, such as Compare to Ancestor and Commit, use the local repository. This diagram represents the Git workflow.

Push

To commit all changes to the local repository, right-click the white space of the Current Folder browser and select Source Control > Commit All to Git Repository. If you have installed a command-line Git client, you can select Source Control > Commit Selection to Git Repository.

To see if your local changes have moved ahead of the remote tracking branch, right-click the file or white space of the Current Folder browser and select Source Control > View Details. The Git information field indicates whether your committed local changes are ahead of, behind, or coincident with the remote tracking branch.

To send local commits to the remote repository, right-click in the Current Folder browser and select Source Control > Push. A message appears if you cannot push your changes directly because the repository has moved on. Right-click in the Current Folder browser and select Source Control > Fetch to fetch all changes from the remote repository. Merge branches and resolve conflicts, and then you can push your changes.

Using Git, you cannot add empty folders to source control, so you cannot select Push and then clone an empty folder. You can create an empty folder in MATLAB, but if you push changes and then sync a new sandbox, then the empty folder does not appear in the new sandbox. To push empty folders to the repository for other users to sync, create a gitignore file in the folder and then push your changes.

Fetch and Merge

To fetch changes from the remote repository, right-click in the Current Folder browser and select Source Control > Fetch. Fetch updates all of the origin branches in the local repository. Your sandbox files do not change. To see others' changes, you need to merge in the origin changes to your local branches.

For information about your current branch relative to the remote tracking branch in the repository, right-click the file or white space of the Current Folder browser and select Source Control > View Details. The Git information field indicates whether your committed local changes are ahead of, behind, or coincident with the remote tracking branch. When you see the message Behind, you need to merge in changes from the repository to your local branch.

For example, if you are on the master branch, get all changes from the master branch in the remote repository.

  1. Right-click in the Current Folder browser and select Source Control > Fetch

  2. Right-click in the Current Folder browser and select Source Control > Manage Branches.

  3. In the Manage Branches dialog box, select origin/master in the Branches list.

  4. Click Merge. The origin branch changes merge into the master branch in your sandbox.

If you right-click the Current Folder browser and select Source Control > View Details, the Git information field indicates Coincident with /origin/master. You can now view the changes that you fetched and merged from the remote repository in your local sandbox.

Related Examples

Was this topic helpful?