Social Collaboration: Using Git for Model-Based Design
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:
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.
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.
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.
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.
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.
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.
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.
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.