---
title: How to List and Create Branches in Git
url: https://docs.vultr.com/how-to-list-and-create-branches-in-git
description: Learn how to efficiently list and create branches in Git with step-by-step instructions for both beginners and experienced developers. Master Git branching today.
publish_date: 2025-08-13T14:40:02.536181Z
last_updated: 2025-08-13T15:21:21.732715Z
author: Roshan Ray
header_image: https://sjc1.vultrobjects.com/docs-main-doc-assets-1/2278/70541633-dec2-4523-b45f-46e570c8acdf.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Branches in Git isolate development work so you can make changes without affecting your main codebase. Listing branches reveals all the available lines of development in your repository. Creating a new branch lets you experiment, fix bugs, or build features independently from stable code.

This article explains how the `git branch` command lists local and remote branches and how to create new branches effectively using Git.

## The Short Answer Version

If you're already familiar with Git and just need a quick reference, use the following commands to list and create branches:

```

# List all local branches
$ git branch

# List remote branches
$ git branch -r

# List both local and remote branches
$ git branch -a

# Create a new branch
$ git branch <new-branch-name>
```

## Common Options for `git branch`

The `git branch` command supports several useful flags for managing and inspecting branches:

| Flag          | Description                                                              |
| ------------- | ------------------------------------------------------------------------ |
| `-r`          | List remote branches only.                                               |
| `-a`          | Show all branches, including local and remote.                           |
| `-m`          | Rename the current or specified branch.                                  |
| `-d`          | Delete a branch (safe delete, only if the branch has been fully merged). |
| `-D`          | Force-delete a branch, even if it contains unmerged changes.             |
| `--merged`    | Show branches that have already been merged into the current branch.     |
| `--no-merged` | Show branches that have not been merged into the current branch.         |
| `-v`          | Show the latest commit on each branch.                                   |

## Create a New Branch

Creating a new branch in Git allows you to isolate development work such as bug fixes or feature additions from the main codebase.

### Command Syntax

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

* `git`: Invokes the Git command-line tool.
* `branch`: Manages local branches.
* `<branch-name>`: The name of the branch to create.

### Command Demonstration

1. List all local branches.

    ```console
    $ git branch
    ```

    Output:

    ```
     hotfix-header
    * main
    ```

    The asterisk indicates that you're currently on the `main` branch.

1. Create a new branch named `feature-login`.

    ```console
    $ git branch feature-login
    ```

    Git creates the new branch from the current `main` branch tip.

1. List the branches again to verify.

    ```console
    $ git branch
    ```

    Output:

    ```
     feature-login
     hotfix-header
    * main
    ```

    The new `feature-login` branch appears alongside existing ones.

## Switching Between Branches

Use the `git switch` command (available in Git 2.23 and later) to change your current working branch. This updates the working directory to reflect the state of the selected branch.

### Command Syntax

```
git switch <branch-name>
```

* `git switch`: Changes the current working branch.
* `<branch-name>`: The name of the target branch.

### Switch to an Existing Branch

1. Check the current branch.

    ```console
    $ git branch
    ```

    Output:

    ```
     feature-login
     hotfix-header
    * main
    ```

    The asterisk marks the current branch (`main`).

1. Switch to the `hotfix-header` branch.

    ```console
    $ git switch hotfix-header
    ```

    Output:

    ```
    Switched to branch 'hotfix-header'
    ```

1. Confirm the active branch.

    ```console
    $ git branch
    ```

    Output:

    ```
     feature-login
    * hotfix-header
     main
    ```

    The asterisk now points to `hotfix-header`.

### Switch to a New Branch

1. Use the `-c` flag with `git switch` to create and switch to a new branch in one step.

    ```console
    $ git switch -c development
    ```

    This creates a new branch named `development` from the current branch and makes it the active branch.

1. Confirm the branch switch.

    ```console
    $ git branch
    ```

    Output:

    ```
    * development
      feature-login
      hotfix-header
      main
    ```

    The asterisk now points to `development`.

### Switch to a Remote Branch

To track and switch to a remote branch that doesn’t exist locally:

1. Fetch the remote branches.

    ```console
    $ git fetch --all
    ```

1. List available remote branches.

    ```console
    $ git branch -r
    ```

    Output:

    ```
    origin/main
    origin/feature-oauth
    ...
    ```

1. Create a local tracking branch and switch to it.

    ```console
    $ git switch --track origin/feature-oauth
    ```

    Git checks out a new local branch named `feature-oauth` linked to `origin/feature-oauth`.

1. Confirm the switch.

    ```console
    $ git branch
    ```

    Output:

    ```
     ...
    * feature-oauth
     feature-login
     hotfix-header
     main
    ```

## Create an Emergency Branch

An emergency branch is a temporary branch created to isolate urgent fixes, such as production outages, security patches, or critical bugs. This approach allows you to address the issue without disrupting ongoing work in `main` or feature branches.

### Command Syntax

```
git switch -c <emergency-branch-name>
```

* `-c`: Creates a new branch before switching.
* `<emergency-branch-name>`: The name of the emergency branch to create.

### Workflow

1. Create and switch to an emergency branch.

    ```console
    $ git switch -c emergency-fix
    ```

    This command creates a new branch named `emergency-fix` and makes it the active branch.

1. After committing your changes, switch back to the `main` branch.

    ```console
    $ git switch main
    ```

1. Merge the emergency branch into `main`.

    ```console
    $ git merge emergency-fix
    ```

1. Once merged, delete the emergency branch to keep your branch list clean.

    ```console
    $ git branch -d emergency-fix
    ```

    For a detailed article on deleting branches, see [How to Delete a Branch in Git](https://docs.vultr.com/how-to-delete-a-branch-in-git).

## Conclusion

In this article, you explored how to list and create Git branches using the `git branch` and `git switch` commands. You also learned how to switch between branches, handle remote tracking, and manage emergency fixes with temporary branches. These techniques help streamline your development workflow, isolate changes safely, and support collaborative Git practices. For advanced usage and configuration, refer to the [official Git documentation](https://git-scm.com/docs/git-branch).
