• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Everything You Need To Know About Git Checkout -b

Jess Wang

Thumbnail for Everything You Need To Know About Git Checkout -bThumbnail for Everything You Need To Know About Git Checkout -bThumbnail for Everything You Need To Know About Git Checkout -bThumbnail for Everything You Need To Know About Git Checkout -b
Everything You Need To Know About Git Checkout -b

“Git checkout -b” is a command that you need to know when you’re learning to code. It’s actually very simple, and this blog will teach you everything you need to know.

What is "git checkout" ?

Git checkout is a terminal command that allows you to switch between and create git branches. By itself, it doesn't do anything. But prepended onto different commands, it can do a variety of different things.

This is what happens when I run git checkout by itself.

Nothing!

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

GIt checkout

What does the "-b" in "git checkout -b" mean?

The "-b" is a flag that bundles two different commands together.

  • Git branch <new_branch_name>
    This creates a new branch named <new_branch_name>
  • Git checkout <new_branch_name>
    This switches you from your current branch to the new branch named <new_branch_name>

I went ahead and ran these commands on my local environment. Here is what the output looks like.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Git branch & Git checkout

‍What happens when I run "git checkout -b" ?

Git checkout -b is a command that will create a new branch and switch you into that new branch from your current branch. I went ahead and ran the command in my local environment to show you what you should be seeing as your output. Here is what the output looks like.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Git checkout -b

As you can see, this command does exactly the same thing as the previous image, but it's a lot shorter, quicker to type, and easier to remember.

How do I use "git checkout -b" ?

One common use case is creating a new local git branch with git checkout -b, and then pushing it to a remote server to create a remote branch of the same name.

Here are the exact commands you need to run to do this.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Create a new remote git branch

Hope this helped!

You can find links to our socials at the bottom of this page - feel free to tweet us any comments or questions, or join our Discord for any further discussions. Good luck on your developer journey!

Related

Thumbnail for Five misconceptions about AI-powered software developmentThumbnail for Five misconceptions about AI-powered software developmentThumbnail for Five misconceptions about AI-powered software developmentThumbnail for Five misconceptions about AI-powered software development
Five misconceptions about AI-powered software development

Five misconceptions about AI-powered software development

By Warp Team

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null