{"id":313255,"date":"2021-07-31T16:00:16","date_gmt":"2021-07-31T13:00:16","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-create-a-new-branch-in-github\/"},"modified":"2021-07-31T16:00:16","modified_gmt":"2021-07-31T13:00:16","slug":"how-to-create-a-new-branch-in-github","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-create-a-new-branch-in-github\/","title":{"rendered":"#How to Create a New Branch in GitHub"},"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-6a2576cdb92ea\" 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-6a2576cdb92ea\" 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-create-a-new-branch-in-github\/#Whats_a_Branch_Anyway\" >What\u2019s a Branch, Anyway?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-create-a-new-branch-in-github\/#Create_a_New_Branch_from_the_GitHub_Website\" >Create a New Branch from the GitHub Website<\/a><\/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-create-a-new-branch-in-github\/#Create_a_New_Branch_Using_the_Command_Line\" >Create a New Branch Using the Command Line<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Create a New Branch in GitHub&#8221;<\/strong><\/p>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone wp-image-738302 size-full\" srcset=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"GitHub hero\" width=\"1200\" height=\"675\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Working directly in the main branch of a GitHub repository is a very dangerous thing, as you stand the risk of pushing buggy code to production. To avoid this, you should create a branch and work in that. Here\u2019s how.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Whats_a_Branch_Anyway\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"moka_anchor_WhatsaBranch\">What\u2019s a Branch, Anyway?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A branch, at its most basic, is a copy of a Git project that you can change as you like and then combine with the original project.<\/p>\n<p>When you <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/714114\/how-and-why-to-create-a-github-repository\/\">create a new repository in GitHub, there\u2019s one branch by default\u2014the \u201cmain\u201d branch (<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.theserverside.com\/feature\/Why-GitHub-renamed-its-master-branch-to-main\">previously called \u201cmaster\u201d<\/a>). This, as the name implies, is the main container where your production code is stored. That is to say (in most cases, at least), if you push a change directly to the main branch, you\u2019re making a change directly to the working product.<\/p>\n<p>The problem? If you push directly to main, you run the risk of pushing buggy code to the production environment, potentially causing serious issues. That\u2019s why you need to create a separate branch to do your work in (and then later submit that branch for review before it\u2019s merged into the main branch).<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How Writers Can Use GitHub to Store Their Work<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Create_a_New_Branch_from_the_GitHub_Website\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_1\"><a rel=\"nofollow noopener\" target=\"_blank\" name=\"moka_anchor_CreateaBranchFromGitHubWebsite\">Create a New Branch from the GitHub Website<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can create a new branch directly from the GitHub website. First, open any browser, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/\">go to GitHub<\/a>, and then open the repository that you\u2019d like to create a branch in.<\/p>\n<p>Once you\u2019ve accessed the repository, you\u2019ll automatically be in the \u201cCode\u201d tab. A bit below this, click the button that says \u201cMain.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-738282\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/In-the-Code-tab-click-the-button-that-says-Main..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"In the &quot;Code&quot; tab, click the button that says &quot;Main.&quot;\" width=\"543\" height=\"293\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>A small window will appear. Give your branch a name by typing it in the text box and pressing the Enter or Return key. Words should be separated by a dash (<code>-<\/code>) or an underscore (<code>_<\/code>).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-738283\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/Type-a-branch-name-in-the-text-box..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Type a branch name in the text box.\" width=\"420\" height=\"337\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Your new branch is now created.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Create_a_New_Branch_Using_the_Command_Line\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_2\"><a rel=\"nofollow noopener\" target=\"_blank\" name=\"moka_anchor_CreateBranchFromCommandLine\">Create a New Branch Using the Command Line<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>At first glance, it might seem easier to just use GitHub from a browser, but once you get the hang of working with GitHub via the command line, things can get done so much quicker. That being said, you can do almost anything in GitHub with the command line\u2014including creating a new branch.<\/p>\n<p>But before you start, you\u2019ll need to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/howtogeek.com\/451360\/how-to-clone-a-github-repository\/\">clone your chosen repository<\/a>\u00a0to your local machine. Go ahead and do that now if you haven\u2019t already.<\/p>\n<p>Once that\u2019s done, open the command line app of your choice. This can be Terminal (if you\u2019re a Mac user) or\u00a0Command Prompt (if you\u2019re a Windows PC user), or you can even work from the built-in command line from a text editor, such as <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/code.visualstudio.com\/\">VSCode<\/a>.<\/p>\n<p>Whichever app you use, you\u2019ll need to navigate to the folder of the repo that you cloned using the <code>cd<\/code>\u00a0command. From the command line, run this command:<\/p>\n<pre>cd &lt;file\/path&gt;<\/pre>\n<p>In our example, that would look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-738286\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/Use-the-cd-command-to-change-to-the-directory-of-your-repo-folder..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Use the cd command to change to the directory of your repo folder.\" width=\"624\" height=\"203\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once you\u2019re in the proper directory, you can then create a new branch. Run this command:<\/p>\n<pre>git checkout -b &lt;your-new-branch-name&gt;<\/pre>\n<p>Replace <code>&lt;your-new-branch-name&gt;<\/code>\u00a0with the actual name that you want to give your branch.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-738290\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/Run-the-command-to-create-a-new-branch..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the command to create a new branch.\" width=\"623\" height=\"236\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Your new branch is now created, but it\u2019s only available on your local machine. You\u2019ll need to push it to the origin repository by running this command:<\/p>\n<pre>git push origin &lt;your-new-branch-name&gt;<\/pre>\n<p>Again, replace <code>&lt;your-new-branch-name&gt;<\/code>\u00a0with the actual name of your branch.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-738291\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/Run-the-command-to-push-your-branch-to-GitHub..png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Run the command to push your branch to GitHub.\" width=\"648\" height=\"237\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ve now pushed your new branch to GitHub!<\/p>\n<p>Working with branches is one of the basics, but it\u2019s also one of the most important GitHub skills to learn. Keep working to master these basics and you\u2019ll be well on your way to becoming fluent in GitHub in no time.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>What Is GitHub, and What Is It Used For?<\/em><\/strong><\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\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.howtogeek.com\/714112\/how-to-create-a-new-branch-in-github\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Create a New Branch in GitHub&#8221; Working directly in the main branch of a GitHub repository is a very dangerous thing, as you stand the risk of pushing buggy code to production. To avoid this, you should create a branch and work in that. Here\u2019s how. What\u2019s a Branch, Anyway? A branch, at&#8230;<\/p>\n","protected":false},"author":1,"featured_media":313256,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-313255","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\/313255","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=313255"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/313255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/313256"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=313255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=313255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=313255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}