Guy and Seth on Simulink

Social Collaboration: Using Git for Model-Based Design 2

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 https://github.com/new 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.

2 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.

Add A Comment

What is 3 + 7?

Preview: hide

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