Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Main Content

Set UpGit Source Control

Since R2025a. ReplacesSet Up Git Source Control (R2024b).

You can use Git™ source control in MATLAB® to manage your files and collaborate with others. Using Git, you can track changes to your files and recall specific versions later. For more information, seeTrack Work Locally with Git in MATLAB andCollaborate Using Git in MATLAB.

Before using Git, follow these steps to set it up for MATLAB:

Starting in R2024a, you can run Git hooks from within MATLAB. Supported hooks arepre-commit,commit-msg,post-commit,prepare-commit-msg,pre-push,pre-merge-commit,post-checkout, andpost-merge. For an example, seeUse Git Hooks in MATLAB.

Register Binary Files withGit

If you use third-party source control tools, you must register your MATLAB and Simulink® file extensions such as.mlx,.mat,.fig,.mlapp,.mdl,.slx,.mdlp,.slxp,.sldd, and.p as binary formats. Also register extensions for MEX files, such as.mexa64,.mexmaci64,.mexmaca64, and.mexw64. If you do not register the extensions, these tools can corrupt your files when you submit them by changing end-of-line characters, expanding tokens, substituting keywords, or attempting to automerge. Corruption can occur if you use the source control tools outside of MATLAB or if you try submitting files from MATLAB without first registering your file formats.

Also register other file extensions, such as.xlsx,.jpg,.pdf, and.docx, as binary formats to avoid corruption during the check-in operation.

To register your binary file extensions with Git, add them to the.gitattributes file in your repository. If you create a new project that uses Git source control or switch an existing project from another source control system to Git source control, MATLAB automatically creates a.gitattributes file and populates it with a list of common binary files to register.

If a.gitattributes file is not automatically created, you can create one that contains the list of common binary files to register. In the MATLAB Command Window, enter:

copyfile(fullfile(matlabroot,'toolbox','shared','cmlink','git','auxiliary_files',...'mwgitattributes'),fullfile(pwd,'.gitattributes'))

Alternatively, create a blank.gitattributes file in your repository and populate its content.

  1. Add* text=auto to the top of the.gitattributes file.

  2. For every binary file extensionext, add*.ext binary. For example,*.mlapp binary.

Enable Support for Long Paths

Enable support for long paths on a Windows system by following these steps.

  1. On theHome tab, in theEnvironment section, clickSettings. SelectMATLAB >Source Control >Git.

  2. In theWindows section, selectEnable support for long paths. Doing so sets the value ofcore.longpaths totrue in your global Git configuration file.

For more information, seeConfigure Git Settings.

Enable Signing Commits

Configure your source control settings to enable MATLAB to sign Git commits automatically by following these steps. When MATLAB verifies a commit signature, a green verification icon appears next to your avatar and username in both theBranch Manager and the line annotations in the MATLAB Editor.

  1. On theHome tab, in theEnvironment section, clickSettings. SelectMATLAB >Source Control >Git.

  2. In theCommit Signing section, set the signing key, the signing key format, and the signing program. For more information, seeConfigure Git Settings.

ConfigureMATLAB to UseGit SSH Authentication

To prevent frequent login prompts when you interact with your remote repository using HTTPS, add a new public key and clone the repository using SSH instead. Configure MATLAB to use SSH authentication by following these steps.

  1. Generate an SSH key using thessh-keygen command. For example, at a command prompt, enter this command:

    ssh-keygen -t ed25519 -C "your_email@example.com"
    ssh-keygen prompts you to confirm where to save the key and asks for a pass-phrase. If you do not want to type a password when you use the key, leave the pass-phrase empty.

    If you already have keys in the specified folder,ssh-keygen asks if you want to override them.

  2. Set up the use of SSH keys in MATLAB. On theHome tab, in theEnvironment section, clickSettings. SelectMATLAB >Source Control >Git. Then, configure your settings.

    1. In theSSH section, if not enabled, selectEnable SSH.

      By default, MATLAB looks for keys in an SSH agent. On Windows, use OpenSSH as the SSH agent. For more information, seeKey-based authentication in OpenSSH for Windows.

      Using an SSH agent enables you to store and use multiple keys.

    2. If you are not using an SSH agent to store your keys, you can enter them manually. Clear theUse SSH agent checkbox. Then, specify the path to your public and private key files inPublic key file andPrivate key file. For more information, seeConfigure Git Settings.

      To enable the use of a pass-phrase and receive a prompt once per session, selectKey is pass-phrase protected.

  3. Configure your GitHub® or GitLab® account to use the SSH keys. To do so, go to the.ssh folder and copy the contents of the.pub file. Then, go to your account settings, and in theSSH keys section, paste the contents of the.pub file into theAdd SSH key field.

ManageGit Credentials

By default, MATLAB remembers your user names and tokens when you interact with Git repositories. To change the default credentials preference, on theHome tab, in theEnvironment section, clickSettings. SelectMATLAB >Source Control >Git. In theCredentials section, choose one of the available options. For more information, seeConfigure Git Settings.

Alternatively, you can install an external Git credential helper and configure MATLAB to use it instead. The recommended credential helper for all platforms is Git Credential Manager Core. For more information, see Configure MATLAB to Use Git Credential Helper inAdditional Setup.

To delete saved login information for a Git repository, in MATLAB, enter:

matlab.git.clearCredential("https://github.com/myrepo.git")

ConfigureGit to UseGit LFS

If you are working with large files, configure Git to use Git Large File Storage (LFS) by installing command-line Git and setting up LFS.

For example, to use Git LFS on a Windows system, download and run the Git for Windows installer using the instructions described under Install Command-Line Git Client inAdditional Setup. In theSelect Components section of the Git for Windows installer, select theGit LFS (Large File Support) andAssociate .sh files to be run with Bash options.

Additional Setup

  • To use Git LFS or a credential helper, you must install a command-line Git client and make it available system-wide.

     Install Command-Line Git Client

    To check if Git is installed, enter the command!git in the MATLAB Command Window. If the command does not return an output, you need to install a command-line Git client. This table provides instructions on how to install a command-line Git client based on your operating system.

    Operating SystemInstructions
    Windows
    1. Download and run the installer fromhttps://gitforwindows.org/.

    2. In theSelect Components sections, make sure you selectGit LFS andAssociate .sh file to be run with Bash.

      • SelectingGit LFS enables you to use Git LFS on Windows.

      • SelectingAssociate .sh file to be run with Bash enables you to use Git hooks on Windows. For an example on how to use Git hooks, seeUse Git Hooks in MATLAB.

      • By default, Git command-line installation includes Git bash that provides shell utilities. When you configure MATLAB to automatically merge Simulink models, Git bash enables you to runmlAutoMerge.bat on Windows. SeeAutomatically Merge Models Locally and in CI Pipeline (Simulink)

    3. In theAdjusting your PATH environment section, choose the install optionGit from the command line and also from 3rd-party software. This option adds Git to yourPATH variable and makes it available system-wide so that MATLAB can communicate with Git.

    4. In the section for configuring the line-ending conversions, choose theCheckout Windows-style, commit Unix-style line endings option. The line-ending format is not enforceable between machines and users, but you can support consistent line endings for text files in the.gitattributes file of each repository.

    5. Restart your system for the changes to take effect.

    Linux®

    Git is available for most distributions. Install Git for your distribution. For example, on Debian®, install Git by entering this command:

    sudo apt-get install git
    macOSOn Mavericks (10.9) or above, run Git from a Terminal window. If you do not have Git installed already, it will prompt you to install Xcode Command Line Tools. For more information, seehttps://git-scm.com/doc.
  • MATLAB remembers your usernames and tokens when you interact with Git repositories. You can use an external Git credential helper to store your Git credentials instead. The Git Credential Manager Core is the recommended credential helper for all platforms.

     ConfigureMATLAB to UseGit Credential Helper

    To install Git Credential Manager Core on a Windows system and configure MATLAB to use it to store Git credentials, follow these steps:

    1. Download and run the Git for Windows installer using the instructions described in the above section.

    2. In theChoose a credential helper section of the installer, selectGit Credential Manager Core as the credential helper. This defines the value ofcredential.helper in your global.gitconfig file.

      Alternatively, you can set the value ofcredential.helper in your global.gitconfig file manually.

See Also

Functions

Topics

MathWorksMathWorks

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

Asia Pacific

Contact your local office


[8]ページ先頭

©2009-2025 Movatter.jp