{"id":366005,"date":"2021-11-12T14:00:24","date_gmt":"2021-11-12T11:00:24","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/"},"modified":"2021-11-12T14:00:24","modified_gmt":"2021-11-12T11:00:24","slug":"how-to-properly-fork-a-github-repository-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/","title":{"rendered":"#How To Properly Fork a Github Repository \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a26e4aa51ba2\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" 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: #dd3333;color:#dd3333\" 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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a26e4aa51ba2\" checked aria-label=\"Toggle\" \/><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:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/#Forking_From_Github\" >Forking From Github<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/#Configuring_The_Forks_Upstream_Remote\" >Configuring The Fork\u2019s Upstream Remote<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/#Forking_From_Git_CLI\" >Forking From Git CLI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/#Updating_With_New_Changes\" >Updating With New Changes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-properly-fork-a-github-repository-cloudsavvy-it\/#Making_Pull_Requests\" >Making Pull Requests<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How To Properly Fork a Github Repository \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-7125\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Open source programming is all about being able to make your own changes to code others have written. To do that, you must branch off from the main repository, commonly called \u201cforking\u201d the repo, but it can be complicated if you don\u2019t do it properly.<\/p>\n<p>While this specifically <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>lies to Github, as it is by far the biggest place for open source collaboration, the same principles will hold for Git repositories forked from any source. Github simply has extra tools that make some tasks easier, but if you prefer Git commands, we will show those as well.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Forking_From_Github\"><\/span>Forking From Github<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you\u2019re using Github, the easiest method to fork a repository is to click the \u201cFork\u201d button, which will automatically make a new repository in your account and set up the remotes when you clone it. This will also make it show up in the \u201cforks\u201d tab of the source repo, and will show on your repo as \u201cforked from X.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14642\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/8f84e8a9.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"423\" height=\"150\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you don\u2019t want that showing up, or aren\u2019t using Github, you\u2019ll need to clone manually.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14641\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/ffff2a92.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"428\" height=\"213\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you are cloning it yourself, make sure to clone the repository properly rather than doing \u201cDownload ZIP.\u201d If you don\u2019t clone it through Git, it won\u2019t copy over the version history and won\u2019t be configured as a Git repository.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configuring_The_Forks_Upstream_Remote\"><\/span>Configuring The Fork\u2019s Upstream Remote<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you forked the repository from the Github website, the <code>origin<\/code>\u00a0remote will point to your fork. However, it\u2019s also useful to be able to pull from the original source repository, called the \u201cupstream.\u201d If they make changes, you\u2019ll probably want to merge or rebase with the upstream remote.<\/p>\n<p>Github has tools built in to do this automatically, so you don\u2019t have to do this part, but if you want to use CLI tools, you\u2019ll need to add back the original repo as a\u00a0remote called \u201c<code>upstream<\/code>\u201c:<\/p>\n<pre>git remote add upstream https:\/\/github.com\/author\/original.git<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Forking_From_Git_CLI\"><\/span>Forking From Git CLI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you downloaded or cloned it from elsewhere, your repository will still be linked to the remote you cloned it from. This is likely what has happened if you downloaded a repo before intending to fork it. Luckily, this is perfectly fine, and you will simply need to configure it yourself.<\/p>\n<p>If you want to integrate new changes from the source, you\u2019ll still want the source remote, but it shouldn\u2019t be the default \u201corigin\u201d remote. So, you\u2019ll want to rename the default remote from \u201c<code>origin<\/code>\u201d to \u201c<code>upstream<\/code>.\u201d<\/p>\n<pre>git remote rename origin upstream<\/pre>\n<p>And then add your own remote as the new \u201c<code>origin<\/code>,\u201d which you will probably need to make manually if you plan on pushing it back to Github:<\/p>\n<pre>git remote add origin\u00a0https:\/\/github.com\/author\/ForkName<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14643\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/fac4e3ed.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"755\" height=\"215\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once that\u2019s done, you\u2019ll probably need to set the default remote for each branch to your fork:<\/p>\n<pre>git branch --set-upstream-to origin<\/pre>\n<p>And push to origin, which will upload the files to your new repository.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Updating_With_New_Changes\"><\/span>Updating With New Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you forked from Github, one of the nice features is that it keeps track of the upstream source and allows you to perform merges through the Github website. It\u2019ll show you when it\u2019s up to date, and when it isn\u2019t, you\u2019ll have the option to merge.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14644\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/e37fbf70.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"902\" height=\"304\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you want to do it through the Git CLI though, there is a better way. Rebasing is similar to merging, but keeps a flat commit heirarchy and doesn\u2019t lead to unnecessary merge commits. Most of the time, you\u2019ll want to rebase when integrating upstream changes, but this is up to you. Merging is also a valid strategy, especially if you\u2019re not merging very often.<\/p>\n<p>To integrate changes, you will need to fetch the <code>upstream<\/code>\u00a0remote, checkout the <code>master<\/code>\u00a0branch, and rebase to <code>upstream\/master<\/code>.<\/p>\n<pre>git fetch upstream&#13;\n&#13;\ngit checkout master&#13;\n&#13;\ngit rebase upstream\/master<\/pre>\n<p>After this, you may need to force push if this is the first time rebasing:<\/p>\n<pre>git push -f origin master<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Making_Pull_Requests\"><\/span>Making Pull Requests<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you forked from Github, this is also easy. You can simply press \u201cContribute\u201d and it will automatically open a pull request.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14645\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/5b917367.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"494\" height=\"258\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If not, the process is still simple. Head to the upstream repository, and under the \u201cPull Requests\u201d tab, select \u201cNew Pull Request.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14646\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/10256416.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"720\" height=\"304\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Then, you will need to select \u201ccompare across forks\u201d and find your fork repository. Select the branches you want to merge, and click \u201cCreate pull request.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14647\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/dac13691.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1370\" height=\"666\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can continue working on your fork, and merging in pull requests as needed. If you\u2019re doing this a lot, you may want to consider setting up your own branches locally for your features, and then merging into the target upstream branch when you want to make a PR. This can help with keeping PRs on topic and focused on one feature branch at a time.\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14640\/how-to-properly-fork-a-github-repository\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How To Properly Fork a Github Repository \u2013 CloudSavvy IT&#8221; Open source programming is all about being able to make your own changes to code others have written. To do that, you must branch off from the main repository, commonly called \u201cforking\u201d the repo, but it can be complicated if you don\u2019t do it properly&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":366006,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-366005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/366005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=366005"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/366005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/366006"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=366005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=366005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=366005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}