Creating a New Branch in GitHub Made Effortless
Tags: github, git
Published: 2020-10-12 11:30:00

---
title: Creating a New Branch in GitHub Made Effortless
published: true
date: 2020-10-09 14:35:09 UTC
tags: GitHub,Git
canonical_url: https://rovitpm.com/how-to-create-a-new-branch-in-github/
---

 ![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/creating-branch-in-github.png)

It took me a while to understand the importance of branches and how they work.

To most developers, this must sound all too familiar. That’s why I’m going to break it down for you. No more confusion and no more double-checks.

Branches in GitHub (and Git) allow you to take the original codebase, create an exact replica of it, make changes, and then submit your changes to be merged into the original code base.

This way, you can make sure the final code base is always bug-free. Or at least not disastrous.

In our previous articles, we covered some of the [basic git commands](https://rovitpm.com/13-git-commands/) and saw how you can improve your development process with [git workflows](https://rovitpm.com//5-git-workflows-to-improve-development/).

* * *

## How Branches in GitHub and Git Work


GitHub (and Git) enables you to control which version of the code gets deployed to your production.

And branches play a fundamental role in this.

Every time you deploy code to production, you’ll obviously want to make sure you’re only deploying the most stable version.

_But how do you make sure you always have a stable version ready for deploy when you’ve got multiple teammates constantly working on new features and bug fixes?_

By creating multiple branches.

Every repository (ie. your code base) in GitHub can have multiple branches.

The main branch, often called the Master branch, is the official stable version of your code. This is the branch that gets deployed to production.

**And it’s also the branch that’s never edited directly. Especially when you’re working collaboratively.**

So when you want to make changes, you’d create a new branch from the master branch, make your changes in it, and when you’re ready, you’d request your changes to be merged into the master branch.

Here’s a visual example of how working with multiple branches might look like:

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/05/feature-branch-with-develop-git-workflow-2.png)<figcaption>Git workflow with feature and develop branches</figcaption>

Which brings us to the question of how to create a new branch in GitHub?

There are three ways you can create a new branch in GitHub:

1. Using GitHub's website.
2. Using GitHub's desktop app.
3. Using command line.

Let’s dive in and look at all three of them.

* * *
<!--kg-card-begin: html-->
## Creating a New Branch From GitHub Website
<!--kg-card-end: html-->

Navigate to the main page of the GitHub repository for which you want to create a new branch.

You’ll see the name of your current branch in the branch selector dropdown. _To see all the branches in the repository, click on [NUMBER Branches]. In my case, you can see that I’m currently on Master branch and I have 2 branches._

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/github-view-all-branches.png)<figcaption>Viewing all branches in your GitHub repository</figcaption>

To create a new branch, click on the branch selector dropdown and start typing the name of the new branch in the text box.

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/github-branch-selector-dropdown.png)<figcaption>Type the name of your new GitHub branch in the search box</figcaption>

By default, this text box checks if there’s an existing branch with the name you just entered.

If not, you’ll be able to create a new branch by selecting “_Create Branch_”.

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/create-new-branch-on-github-website.png)<figcaption>Click create branch</figcaption>

This will automatically create a new branch with the Master branch as your base branch.

However, to switch and edit your code from the new branch you just created, you’ll still have to use GitHub’s desktop app or the terminal code. That’s why, most developers prefer to just use the desktop app or work using terminal commands.

Let’s see how you can do that as well, shall we? :)

* * *
<!--kg-card-begin: html-->
## Creating a New Branch Using GitHub Desktop App
<!--kg-card-end: html-->

Creating a new branch on the GitHub Desktop app is identical to how you’d create on the website.

_Make sure you’ve got [GitHub's desktop app downloaded](https://desktop.github.com/) before reading further._

Once you’ve got the desktop app open, navigate to the repository in which you want to create a new branch.

Now, click on the branch selector dropdown and click "_New Branch_" button.

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/github-desktop-app-click-new-branch-button.png)<figcaption>Click the "New Branch" button from the Branch Selector drop down</figcaption>

In the create new branch pop-up, enter the name of your new branch and click the “_Create Branch_” button.

![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/github-desktop-app-click-create-branch-button.png)<figcaption>Enter the name of your branch and click "Create Branch"</figcaption>

Alternatively, you can use the shortcut key `Cmd + Shift + n` (or `Ctrl + Shift + n` if you’re on Windows) to create a new branch.

To begin making changes to this branch, simply hit `Cmd + Shift + a` (or `Ctrl + Shift + a` if you're on Windows) to open your code in your code editor.

It's important to remember that while a new branch might be created, it will not be accessible to everyone unless you publish it to the remote location. You can choose to make all the code changes, commit them, and then publish your branch. Or, you can click on the “_Publish_” button.

_Zepel Tip_

_Oftentimes, a branch is created by the developer when they begin working on a new feature or a new bug-fix._

_Instead of manually updating the team about the progress, developers can automatically change statuses and keep everyone updated_

<img src="https://zepel.io/blog/content/images/2020/01/zepel-git-workflow-automation.png" alt="automate developer workflow using github integration"/>

_All you have to do is, enable the <a href="https://zepel.io/guide/integrations/github/?utm_source=devto&utm_medium=text&utm_campaign=how-to-create-branch-in-github">GitHub integration</a> with Zepel, edit your workflow, and <a href="https://zepel.io/guide/integrations/link-item-to-branch/?utm_source=devto&utm_medium=text&utm_campaign=how-to-create-branch-in-github">link your work item to your branch</a>._

<!--kg-card-end: html-->
* * *
<!--kg-card-begin: html-->
## Using Command Line to Create New Branch in GitHub
<!--kg-card-end: html-->

Creating a new branch using the command line is nearly every developer’s favourite method. Because once you get a hang of it, it’s unbelievably easy to use.

First, make sure to `cd` into your local repository. Once you’re in the right folder, execute

```
$ git branch <branch-name>
```

This will create a new branch. But before you start making changes to your code, you will have to first switch to the new branch you just created. To do that, run

```
$ git checkout <branch-name>
```

Many developers, especially when they’re just getting started, forget switching to the new branch. That’s why you can use this command that will create the new branch and immediately switch you to it:

```
$ git checkout -b <branch-name>
```

Once you’ve created a new branch and switched to it, you can start making changes in your code. However, all of these changes (including the new branch) is still only in your local machine.

To publish the new branch you created in GitHub and make it available for everyone in your team, run the following command:

```
$ git push -u <remote> <branch-name>
```
<!--kg-card-begin: html-->


_Zepel Tip_ 

_If you use Zepel as your [agile project management tool](https://zepel.io/agile-tools/?utm_source=devto&utm_medium=text&utm_campaign=how-to-create-branch-in-github), you can create a new Feature for every feature you build._
  
_With the help of deep GitHub integration, you can [link the Feature to a branch in GitHub](https://zepel.io/guide/integrations/link-features-to-branch/?utm_source=devto&utm_medium=text&utm_campaign=how-to-create-branch-in-github) and Zepel will automatically update progress within your team._
  
_Say you're working on Public API for your product. You'll create a feature called Public API in Zepel, create tasks for it, and link the feature to your new Branch using the command suggested by Zepel: ![Creating a New Branch in GitHub Made Effortless](https://zepel.io/blog/content/images/2020/10/zepel-github-link-feature-to-branch.png)This way, you can spend all your time building quality software while Zepel does the grunt work for you._

<!--kg-card-end: html-->
* * *

With Branches in Git and GitHub, working on code collaboratively is a lot easier than it used to be. While there can still be inefficiencies in your development workflow, a lot of it depends on the intricacies of it.

However, if I must leave you with one thing, never directly make changes to your master branch. Nothing good has ever come off it.