# Switching Branches Using Git Switch

> In this post, we will walk through everything you need to know about one of the sub-commands that are part of git, the git switch command.

- Author: [CJ Saathoff](https://www.namehero.com/blog/author/cj-saathoff/)
- Published: 2025-02-13
- Updated: 2025-02-13
- Category: [Website Development](https://www.namehero.com/blog/category/website-development/)
- Web page: https://www.namehero.com/blog/switching-branches-using-git-switch/

[![](https://blogcdn.namehero.com/blog/wp-content/uploads/2025/02/07085855/switchingbranches-1024x576.jpg)](https://blogcdn.namehero.com/blog/wp-content/uploads/2025/02/07085855/switchingbranches.jpg)

In this post, we will look at one of the sub-commands that are part of git, the [git switch](https://git-scm.com/docs/git-switch) command. Before we get into things, though, let me clarify a few things. Git is a [distributed version control system](https://en.wikipedia.org/wiki/Distributed_version_control) primarily used for tracking changes in source code during software development. A branch is a separate line of development within a repository. The switch sub-command which is what we’re looking at today is used to switch to a specified branch of development.

## Basic Usage

Basic usage of the git switch command is as follows:

```

 git switch [&lt;options>] [&lt;branch>]

```

We start with git switch, followed by any options, and then the branch name.

## Flags

Below are my picks from the commands help text, for an exhaustive list please refer to the man page or [git’s website](https://git-scm.com/).

>

-c, –create

create and switch to a new branch

–discard-changes

discard away local modifications

-q, –quiet

suppress progress reporting

–progress

force progress reporting

-m, –merge

perform a 3-way merge with the new branch

–conflict <style>

conflict style (merge, diff3, or zdiff3)

-f, –force

force checkout (throw away local modifications

## Examples

Below are some examples I feel are the most useful.

### **Switching To An Existing Branch**

To switch to an existing branch, use the following command:

```

git switch &lt;branch-name>

```

This command changes the context of your work to the specified branch, allowing you to work with the files and commit history of that branch.

### Create A New Branch From A Different Branch

You can create a new branch based on a different branch as follows:

```

 git switch remotes/origin/example -c hello-world

```

This command switches to the remote branch name example from the remote origin and creates a new branch from that branch.

### Switch To The Previous Branch

To switch to the previous branch, use the following command:

```

git switch -

```

This command is a short way to switch back to the branch you were working on before the current one.

### Switch To A Branch And Automatically Merge The Current Branch (Including Uncommitted Changes)

To merge while you switch branches, try this command:

```

git switch --merge branch-name

```

This command switches to a specified branch while merging any changes from your current branch.

## Conclusion

In this post, we looked at one of the many sub-commands which are part of git, the [git switch](https://git-scm.com/docs/git-switch) command. We covered basic usage, flags of the command, and examples. Proving that the switch sub-command can be used for more than just switching to a different local branch, such as to checkout remote branches, and to create a new branch.

## Looking For More

Are you looking for more and a place to start? If so, why not check out our other gits posts?

- [Other Git Related Posts](https://www.namehero.com/blog/?s=git)

## Related posts

- [Git Checkout vs. Switch: What’s The Difference?](https://www.namehero.com/blog/git-checkout-vs-switch-whats-the-difference/)
- [How To List Remote Branches In A Git Repository](https://www.namehero.com/blog/how-to-list-remote-branches-in-a-git-repository/)
- [How to Create A Lead Capture Page That Converts](https://www.namehero.com/blog/how-to-create-a-lead-capture-page-that-converts/)
