Guy and Seth on Simulink

Social Collaboration: Using Git for Model-Based Design 3

Posted by Guy Rouleau,

This week, Matt Brauer is back to talk about Git Integration in Simulink Projects, and how he used it to share his Hyperloop simulation on GitHub.

Simulink Projects Git Integration

Simulink Projects was introduced in R2011b to support effective collaboration across teams. Until now, the focus has been teams within an organization. With the introduction of Git integration in R2014a you can expand your team using social collaboration sites such as GitHub.

This new functionality is ideal for crowd-sourced development projects. With that in mind, I published our Simulink model of the Hyperloop onto GitHub. Here’s how I did it.

Creating a new Simulink Project on GitHub

To create a new Simulink Project to be shared on GitHub, I had to start by creating the new repository on GitHub. The URL of that repository is needed when creating the Simulink Project. Starting at I went ahead as below:

Creating an empty repository on GitHub and copying the URL

Once I had the empty repository on GitHub, I went to MATLAB and set up a New > Simulink Project > From Source Control. This opened the Project Retriever window below. I set Git as the Source control integration and pasted the URL as the Repository path.

Project Retriever with link to public GitHub repository

Once I had the local Simulink Project, I could begin adding content in my sandbox (or “working tree” if you’re fluent in git-ish). To publish the content, I first had to Commit the modified files to my local repository and then Push that repository out to GitHub.

Publishing changes from Simulink Projects

Contributing to an existing GitHub repository

Although GitHub is designed for open, social collaboration, it’s not completely without access restrictions. To modify a repository on GitHub, you must be the owner or defined as a collaborator. Collaborators are defined in the Settings of the repository.

If you’re interested in making contributions to an interesting repository (a revolutionary transportation concept, for example), you must first create your own Fork, or copy.

Creating your own fork of the hyperloop_sl repository on GitHub (may not view well in IE)

If you’re confused about Branches and Forks, take a look at the graphic below. If you’re like me, you’ll need to print it out and sleep with it under your pillow.

Simulink Projects and GitHub workflows

Once you’ve created your own Fork, follow the same steps as a new repository to load the project into Simulink. You can freely Push your changes out to your own Forked repository.

If you think your changes are really great and should be included in the original repository, create a Pull Request in GitHub. The owner of the original repository will be alerted via e-mail about your desire to contribute.

Accepting contributions

I was lucky enough to have a contributor (some Guy who knows a lot about SimMechanics) improve my calculation for passenger g-forces in their local frame. You can see the e-mail that I received when he submitted a Pull Request.

Sample Pull Request e-mail from GitHub

After accepting the Pull Request in GitHub, I opened my Simulink Project and Fetched the latest archive. But, when I opened up the model, I didn’t see Guy’s updates. That’s because the files in the project window are my Sandbox, which is the Current Branch. I need to merge the updates using Manage Branches. In the Branches pull-down, I found a branch called refs/remotes/origin/master, which is the remote repository that I just Fetched. After clicking Merge I was working with Guy’s contribution.

Managing branches to merge contributions

Now it's your turn

Retreive or fork from Matt's Hyperloop repository, or create your own Simulink Project on GitHub and let us know by leaving a comment here.

3 CommentsOldest to Newest

This is great news but there isn’t any mention to conflict handling.
If some people work in parallel they’re going to have merge conflicts, especially for an open development model.
It’d be great to have some news about this.

Any progress on a tutorial style video for two+ person teams branching, merging, resolving conflicts using the Simulink Report Generator? Perhaps a follow-on to the Simulink Racing Lounge video introducing Git?
We’ve been working on some internal tutorials but some official Matlab videos or Powerpoint walk-throughs would be great.

One thing our team noticed was that when two people are working together using a remote repo: User 1 makes a local branch then pushes the branch to the remote. User 2 needs to make a branch of the same name on their local repo, Switch to it, then Merge the remote branch: refs/remotes/origin/my_branch with their newly created local repo branch my_branch. My understanding is the equivalent would be “$git checkout –track origin/my_branch” in Git Bash. This might not be obvious to new Simulink Project with Git users who haven’t used Git before. Thanks for the writeups so far

Add A Comment

What is 7 + 10?

Preview: hide

These postings are the author's and don't necessarily represent the opinions of MathWorks.