{"id":1160,"date":"2015-03-18T08:54:35","date_gmt":"2015-03-18T08:54:35","guid":{"rendered":"https:\/\/intelligentbee.com\/blog\/?p=1160"},"modified":"2024-08-28T12:24:04","modified_gmt":"2024-08-28T12:24:04","slug":"how-teams-use-git-for-big-projects","status":"publish","type":"post","link":"https:\/\/intelligentbee.com\/blog\/how-teams-use-git-for-big-projects\/","title":{"rendered":"How Teams Use Git for Big Projects"},"content":{"rendered":"<p>Every time a new member joins our team we have to guide him through our Git workflow. So I decided to write everything here in order to simply\u00a0send them the link (and help others interested in learning how a real development team uses Git).<\/p>\n<p><!--more--><\/p>\n<p>So, we will assume you know what Git is, if not, please make sure you read AND understand (at least) the first 3 chapters from here: http:\/\/git-scm.com\/book<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/intelligentbee.com\/blog\/how-teams-use-git-for-big-projects\/#Repositories\" title=\"Repositories\">Repositories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/intelligentbee.com\/blog\/how-teams-use-git-for-big-projects\/#Common_Branches\" title=\"Common Branches\">Common Branches<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Repositories\"><\/span>Repositories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Every project has its own repository owned by the company which we call\u00a0upstream. As you start working on an existing project, you will receive access to its Git repository belonging to your organization&#8217;s\u00a0account on BitBucket or GitHub. When a new developer joins the team and starts to work on this project, he or she will need to make a fork of the upstream repository (from the web interface). This fork is a copy of the original repository, now owned by the developer. This new repository is called origin.<\/p>\n<p><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\">So the first thing to remember is the upstream and origin names and their meaning: <\/span>upstream<span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\"> is the original, company owned, repository, while the <\/span>origin<span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\"> is a\u00a0copy, owned by the developer. Every developer will have his\/hers <\/span>origin<span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\"> repository!<\/span><\/p>\n<p>After you create your fork, you will have to clone the repository (the origin) on your development machine. To do this use the <code>git\u00a0clone<\/code> command:<\/p>\n<pre class=\"theme:terminal nums:false lang:sh decode:true \">git clone [your repo ssh url]<\/pre>\n<p>Now, that you have the origin locally (check with <code>git remote -v<\/code>) let\u2019s also add the upstream:<\/p>\n<pre class=\"theme:terminal nums:false lang:sh decode:true \">git remote add upstream [upstream repo ssh url]<\/pre>\n<p>To see the result, run <code>git remote -v<\/code>. Both origin and upstream should be listed.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_Branches\"><\/span>Common Branches<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We generally use 3 types of branches: master, release and the development branches.<\/p>\n<p>&nbsp;<\/p>\n<p>The <strong>master<\/strong> branch has the code that is currently running in production and the <strong>release<\/strong> gathers all the code ready to be merged into master and deployed live.<\/p>\n<p>&nbsp;<\/p>\n<p>For every task\/story you have to create a new branch from the current release having the name formatted like this:\u00a0<code>[story_ID]-[intuitive name]-[team name (optional)]<\/code>. Note that you will use your origin repository to create new branches so this means you will have to make sure your release branch is up-to-date with the latest code form upstream:<\/p>\n<pre class=\"theme:terminal nums:false lang:sh decode:true \">git checkout release\r\ngit pull upstream release\r\ngit push origin release\r\ngit checkout -b [branch name]<\/pre>\n<h3>Workflow<\/h3>\n<p>As previously stated, when works starts on a new task\/story, a new branch is created from the release branch. You will develop and commit in this branch until you\u2019re done. You are encouraged to commit as often as possible:<\/p>\n<pre class=\"theme:terminal nums:false lang:sh decode:true\">git add [file to be commited]\r\ngit commit -m \u201ccommit message\"\r\ngit push origin [branch name]<\/pre>\n<p>We recommend to check what is to be committed first, by running the <code>git status<\/code> and <code>git diff<\/code> commands, then adding each file individually (or group of files) to the commit.<\/p>\n<blockquote><p><img decoding=\"async\" class=\"alignleft wp-image-1166\" src=\"\/\/intelligentbee.com\/blog\/wp-content\/uploads\/2015\/03\/face-glasses.png\" alt=\"face-glasses\" width=\"60\" height=\"60\" \/>Avoid adding\u00a0everything to the commit because this will often lead to unwanted changes to be committed and your code will fail CR (code review).<br \/>\n<del>git add .<\/del><\/p><\/blockquote>\n<p>When you\u2019re done, push the branch on the upstream repo so others can access it:<\/p>\n<pre class=\"theme:terminal nums:false lang:sh decode:true \">git push upstream [branch name]<\/pre>\n<p>After this, create a <strong>pull request<\/strong> from this new branch to the upstream release branch and send the story to QA and CR (together with the pull request url).<\/p>\n<p>&nbsp;<\/p>\n<p>If everything is ok, the code will be merged into the release branch to test it together with other changes made by you or colleagues developers when working on different stories. When everything is ready to be deployed, the release branch (<strong>the upstream release<\/strong>) will be merged into the master and the code will end up on the production server.<\/p>\n<p>&nbsp;<\/p>\n<p>Congratulations! Now that you know how to use Git, take a break and have a laugh at\u00a0those who don&#8217;t:<\/p>\n<p>&nbsp;<\/p>\n<p><iframe src=\"https:\/\/www.youtube.com\/embed\/CDeG4S-mJts\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every time a new member joins our team we have to guide him through our Git workflow. So I decided [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,86],"tags":[145,149,209,248,253],"yst_prominent_words":[267,394,398,798,1324,1905],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1160"}],"collection":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":5,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"predecessor-version":[{"id":133204,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions\/133204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media\/1163"}],"wp:attachment":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/tags?post=1160"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}