{
    "componentChunkName": "component---src-templates-post-post-tsx",
    "path": "/blog/git-flow",
    "result": {"data":{"post":{"id":"cG9zdDo3OA==","title":"Git flow for a forked repository, a practical solution","slug":"git-flow","uri":"/git-flow/","date":"May 04, 2021 - 19:37","content":"\n<p>Having a git flow is a great idea for each developer who does not want to face with too much of conflicts. So read this post if you need a practical and useful git flow.</p>\n\n\n\n<h2 class=\"wp-block-heading\">Forking</h2>\n\n\n\n<p>If you&#8217;ve been forked a repository from another repository, it&#8217;s recommended to run the following commands after cloning your forked repository:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code>git remote add upstream [base repository address]\n\ngit fetch upstream</code></pre></div>\n\n\n\n<h2 class=\"wp-block-heading\">Common Git Flow</h2>\n\n\n\n<p>This section is a common git flow for those repositories which is forked from another repository, and those which is not. So it doesn&#8217;t matter which one do you use. It&#8217;s recommended to follow the following git flow to decrease the potential risks.</p>\n\n\n\n<h3 class=\"wp-block-heading\">Create new local branch</h3>\n\n\n\n<p>I recommend you to create a local branch for yourself and always coding in that branch:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code># create a new local branch with your custom name, for example &quot;working&quot;&#39;\ngit checkout -b working</code></pre></div>\n\n\n\n<h3 class=\"wp-block-heading\">Committing</h3>\n\n\n\n<p>When you need to commit your changes, you need to do the following commands in your local branch:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code># if you have new files or folders\ngit add .\n\n# if you are working on specific issue, it&#39;s better to mention your issue number in your comment with a hashtag before --&gt; for example [#1]\ngit commit -am &#39;your-comment&#39;</code></pre></div>\n\n\n\n<h3 class=\"wp-block-heading\">Merge &amp; Rebase</h3>\n\n\n\n<p>If you reach a stable version and you need to merge your changes with the parent branch, follow the following flow:</p>\n\n\n\n<ol><li>Checkout to your parent branch:</li></ol>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code># if your parent branch is master\ngit checkout master</code></pre></div>\n\n\n\n<ol start=\"2\"><li>Pull the latest changes:</li></ol>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code># if you are working on a forked repository. Get the latest changes from parent repository\n# if your main branch of your parent repository is master\ngit pull upstream master\n\n# then\ngit pull</code></pre></div>\n\n\n\n<ol start=\"3\"><li>Rebase your local branch:</li></ol>\n\n\n\n<p>a. After finishing the <strong>second step</strong>, if there was updates caused by your pulling, you should get back to your local branch and rebase it from its parent, if not, you can skip the third step:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code>git checkout working\n\ngit rebase master</code></pre></div>\n\n\n\n<p>b. After using rebase command, <strong>if</strong> you face with conflict(s), first of all you should resolve the conflicts and then do the following commands and repeat it again until you not facing with conflict(s) anymore:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code>git add .\n\ngit rebase --continue</code></pre></div>\n\n\n\n<p>c. Getting back to your parent branch:</p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-git\" data-lang=\"Git\"><code>git checkout master</code></pre></div>\n\n\n\n<ol start=\"4\"><li>Merge &amp; Push: Now you can merge your parent ( master ) branch with your local one and then push it to your <a href=\"/blog/category/git\">git</a> repository with following commands:</li></ol>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-git\" data-lang=\"Git\"><code>git merge working\n\ngit push</code></pre></div>\n\n\n\n<h2 class=\"wp-block-heading\">Create a merge request</h2>\n\n\n\n<p>If you use forking, after following the above flow in your forked repository, you should create a merge request in your repository panel, from your forked repository to the main one and wait for reviewer to review it and merge it if it was OK.</p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Flow Recommendation</h2>\n\n\n\n<p>Totally, it&#8217;s good to have a specific git flow for your development team and ask them to follow it. It will help your team to avoid facing with risky situations in pulling and pushing the codes.<br>Hope it being useful.<br>Don&#8217;t forget to share your comments with me.<br>Thanks.</p>\n","author":{"node":{"name":"hamidreza","avatar":{"url":"https://secure.gravatar.com/avatar/c4ef37782a933163dcb8e61b6a02dbbe?s=96&d=mm&r=g","width":96,"height":96}}},"featuredImage":{"node":{"sourceUrl":"https://hramini-back.ir/wp-content/uploads/2021/05/Feature-image.jpg","altText":"fork git flow","srcSet":"https://hramini-back.ir/wp-content/uploads/2021/05/Feature-image-300x158.jpg 300w, https://hramini-back.ir/wp-content/uploads/2021/05/Feature-image-1024x538.jpg 1024w, https://hramini-back.ir/wp-content/uploads/2021/05/Feature-image-768x403.jpg 768w, https://hramini-back.ir/wp-content/uploads/2021/05/Feature-image.jpg 1440w","sizes":"(max-width: 300px) 100vw, 300px","mediaDetails":{"height":756,"width":1440}}},"categories":{"nodes":[{"slug":"git","uri":"/category/git/","name":"Git"}]}}},"pageContext":{"postId":"cG9zdDo3OA==","categoryId":"dGVybToyNA=="}},
    "staticQueryHashes": []}