If you’re like most developers, you probably use GitHub to store your code and collaborate on projects with friends and colleagues. But what if you want to switch to a new branch of development? Or maybe you’re ready to start a new project from scratch? In this article, we’ll show you how to do both of these things using the GitHub interface. To switch branches in GitHub, first open your repository’s page in the web browser. (If you don’t have a repository open, create one by clicking the “New Repository” button on the main page.) On the left side of the page, under “Branches,” click on the branch name that you want to switch to. (For example, if you’re working on a project called “MyProject,” your current branch might be called “master.”) Now click on the “Switch To” button next to the branch name. This will take you to a screen where you can choose which commit message or branch head you want as your starting point for this new branch. (You can also use this screen to create a new commit message or branch head.) Once you’ve made your selection, click on the “Switch To” button again. Now that you’ve switched branches in GitHub, any changes that you make will be reflected in both your old and new branches. If someone else is working on a project with which yours shares some common codebase (for example, if they’re using master as their default branch), they’ll see your changes as soon as they make them and can merge them into their own copy of master without any conflicts arising. ..


To ensure there’s no downtime due to pushing problematic code straight to the main branch on GitHub, you should create a new branch and work there. Before you can actually work there, though, you’ll need to switch to it.

Switch Branches From the GitHub Website

To switch branches from the GitHub website, first launch your preferred browser, go to GitHub’s official website, log in to your account, and then select the repository your branch is in.

RELATED: How (and Why) to Create a GitHub Repository

Once in the repository, you’ll see a button next to the Branches and Tags options. Click this button to display a drop-down menu. In the “Branches” tab, select the desired branch from the list. Once selected, you’ll then be in that branch.

This method is fine if you’re going to make your changes to the branch on the website, but if you’re working on your local machine, you’ll want to use a git command.

Switch Branches Using git checkout

If you’re working locally, you can switch branches using a simple command. To get started, you’ll need to open a command terminal of your choice (for example, Terminal on Mac, Windows Terminal, or the Linux terminal). Alternatively, you can use the command terminal in a text editor that supports it, such as VSCode.

RELATED: How to Make Windows Terminal Your Default Terminal App

Once in the terminal, you’ll want to change directories to the location of the repository. This isn’t a one-size-fits-all command, as everyone may have their repository stored in a different directory on their local machine.

As an example, let’s assume that we’re in the top directory in the terminal, and our repo called how-to-geek is located in the file path OneDrive > Desktop > _GIT. We’d run this command:

You can now switch branches now that you’re in the correct directory. To switch branches, run this command:

So if your branch were named “test-branch” then you would run:

You’ve successfully switched branches.

Switch Branches Using git switch

You can also use the git switch command to switch branches. First, open your desired terminal and change to the proper directory using the cd command. Once in the proper directory, run this command:

So, if our branch name is test-branch then we’d run this command:

You’ll now have successfully switched branches.

 git switch vs. git checkout

At first glance, git checkout and git switch may appear to do the same thing under different names. You’re not far from wrong, but there is a minor difference you should make note of. git checkout provides additional functionality than just switching branches, which is why developers created git switch–to clear the confusion.

git switch only switches to a new branch. That’s it. git checkout, however, does three things: it switches branches, but it also copies files from the stage and from a tree-ish to the working tree. If you’re interested in learning more about this, Dan Fabulich from Redfin Engineering gives a fantastic breakdown.

Working on separate branches (that’s not the main branch) prevents production downtime from poor code being pushed to production. Testing your code in a child branch will save you a world of trouble. And once you merge your branch into the main branch, don’t forget to delete it to keep the repository from being cluttered.

RELATED: How to Delete a Branch on GitHub