{"id":3571,"date":"2014-04-17T09:52:50","date_gmt":"2014-04-17T14:52:50","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3571"},"modified":"2017-01-04T16:03:16","modified_gmt":"2017-01-04T21:03:16","slug":"social-collaboration-using-git-for-model-based-design","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/04\/17\/social-collaboration-using-git-for-model-based-design\/","title":{"rendered":"Social Collaboration: Using Git for Model-Based Design"},"content":{"rendered":"<p><!--introduction--><\/p>\n<p>This week, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/4370178-matt-brauer\">Matt Brauer<\/a> is back to talk about Git Integration in Simulink Projects, and how he used it to share his Hyperloop simulation on GitHub.<\/p>\n<p><!--\/introduction--><\/p>\n<p><strong>Simulink Projects Git Integration<\/strong><\/p>\n<p><a title=\"https:\/\/www.mathworks.com\/discovery\/simulink-projects.html (link no longer works)\">Simulink Projects<\/a> was introduced in R2011b to support effective collaboration across teams. Until now, the focus has been teams within an organization. With the introduction of <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/set-up-git-source-control.html\">Git integration<\/a> in R2014a you can expand your team using social collaboration sites such as <a href=\"http:\/\/github.com\/\">GitHub<\/a>.<\/p>\n<p>This new functionality is ideal for crowd-sourced development projects. With that in mind, I published our <a href=\"https:\/\/blogs.mathworks.com\/seth\/2013\/11\/07\/hyperloop-model-architecture-we-want-your-feedback\">Simulink model of the Hyperloop<\/a> onto GitHub. Here\u2019s how I did it.<\/p>\n<p><strong>Creating a new Simulink Project on GitHub<\/strong><\/p>\n<p>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 ht&#8203;tps:\/\/github.com\/new I went ahead as below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/createRepository.gif\" alt=\"Creating an empty repository on GitHub and copying the URL\" \/><\/p>\n<p>Once I had the empty repository on GitHub, I went to MATLAB and set up a New &gt; Simulink Project &gt; 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/Project Retriever.png\" alt=\"Project Retriever with link to public GitHub repository\" \/><\/p>\n<p>Once I had the local Simulink Project, I could begin adding content in my sandbox (or \u201cworking tree\u201d if you\u2019re 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/commitAndPush.png\" alt=\"Publishing changes from Simulink Projects\" \/><\/p>\n<p><strong>Contributing to an existing GitHub repository<\/strong><\/p>\n<p>Although GitHub is designed for open, social collaboration, it\u2019s 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.<\/p>\n<p>If you\u2019re interested in making contributions to an interesting repository (a revolutionary transportation concept, for example), you must first create your own Fork, or copy.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/forkRepository.gif\" alt=\"Creating your own fork of the hyperloop_sl repository on GitHub (may not view well in IE)\" \/><\/p>\n<p>If you\u2019re confused about Branches and Forks, take a look at the graphic below. If you\u2019re like me, you\u2019ll need to print it out and sleep with it under your pillow.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/slProjects_gitHub_workflow.png\" alt=\"Simulink Projects and GitHub workflows\" \/><\/p>\n<p>Once you\u2019ve 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.<\/p>\n<p>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.<\/p>\n<p><strong>Accepting contributions<\/strong><\/p>\n<p>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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/PullRequestEmail.png\" alt=\"Sample Pull Request e-mail from GitHub\" \/><\/p>\n<p>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\u2019t see Guy\u2019s updates. That\u2019s 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\u2019s contribution.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/manageBranches.png\" alt=\"Managing branches to merge contributions\" \/><\/p>\n<p><strong>Now it's your turn<\/strong><\/p>\n<p>Retreive or fork from <a href=\"https:\/\/github.com\/mabrauer\/hyperloop_sl\">Matt's Hyperloop repository<\/a>, or create your own Simulink Project on GitHub and let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=3571\ufffd\">comment here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/manageBranches.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p><!--introduction--><\/p>\n<p>This week, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/4370178-matt-brauer\">Matt Brauer<\/a> is back to talk about Git Integration in Simulink Projects, and how he used it to share his Hyperloop simulation on GitHub.<\/p>\n<p><!--\/introduction-->... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/04\/17\/social-collaboration-using-git-for-model-based-design\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[34,24],"tags":[376,377,348,378],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3571"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=3571"}],"version-history":[{"count":25,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3571\/revisions"}],"predecessor-version":[{"id":6273,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3571\/revisions\/6273"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}