The answer has been split depending on whether there is one remote repository configured or multiple. The reason for this is that for the single remote case, some of the commands can be simplified as there is less ambiguity.

Updated for Git 2.23: For older versions, see the section at the end.

With One Remote

In both cases, start by fetching from the remote repository to make sure you have all the latest changes downloaded.

$ git fetch

This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a

...
remotes/origin/test

The branches that start with remotes/* can be thought of as read only copies of the remote branches. To work on a branch you need to create a local branch from it. This is done with the Git command switch (since Git 2.23) by giving it the name of the remote branch (minus the remote name):

$ git switch test

In this case Git is guessing (can be disabled with --no-guess) that you are trying to checkout and track the remote branch with the same name.

With Multiple Remotes

In the case where multiple remote repositories exist, the remote repository needs to be explicitly named.

As before, start by fetching the latest remote changes:

$ git fetch origin

This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a

With the remote branches in hand, you now need to check out the branch you are interested in with -c to create a new local branch:

$ git switch -c test origin/test

For more information about using git switch:

$ man git-switch

Prior to Git 2.23

git switch was added in Git 2.23, prior to this git checkout was used to switch branches.

To checkout out with only a single remote repository:

git checkout test

if there are multiple remote repositories configured then it becomes a bit longer

git checkout -b test <name of remote>/test
Answer from hallski on Stack Overflow
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
$ git checkout -b foo # or "git switch -c foo" (1) $ git branch foo (2) $ git tag foo (3) creates a new branch foo, which refers to commit f, and then updates HEAD to refer to branch foo. In other words, we’ll no longer be in detached HEAD state after this command.
Top answer
1 of 16
11978

The answer has been split depending on whether there is one remote repository configured or multiple. The reason for this is that for the single remote case, some of the commands can be simplified as there is less ambiguity.

Updated for Git 2.23: For older versions, see the section at the end.

With One Remote

In both cases, start by fetching from the remote repository to make sure you have all the latest changes downloaded.

$ git fetch

This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a

...
remotes/origin/test

The branches that start with remotes/* can be thought of as read only copies of the remote branches. To work on a branch you need to create a local branch from it. This is done with the Git command switch (since Git 2.23) by giving it the name of the remote branch (minus the remote name):

$ git switch test

In this case Git is guessing (can be disabled with --no-guess) that you are trying to checkout and track the remote branch with the same name.

With Multiple Remotes

In the case where multiple remote repositories exist, the remote repository needs to be explicitly named.

As before, start by fetching the latest remote changes:

$ git fetch origin

This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a

With the remote branches in hand, you now need to check out the branch you are interested in with -c to create a new local branch:

$ git switch -c test origin/test

For more information about using git switch:

$ man git-switch

Prior to Git 2.23

git switch was added in Git 2.23, prior to this git checkout was used to switch branches.

To checkout out with only a single remote repository:

git checkout test

if there are multiple remote repositories configured then it becomes a bit longer

git checkout -b test <name of remote>/test
2 of 16
1565

Sidenote: With modern Git (>= 1.6.6), you are able to use just

git checkout test

(note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.


The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:

git checkout -b test HEAD

A more modern approach as suggested in the comments:

@Dennis: git checkout <non-branch>, for example git checkout origin/test results in detached HEAD / unnamed branch, while git checkout test or git checkout -b test origin/test results in local branch test (with remote-tracking branch origin/test as upstream) – Jakub Narębski Jan 9 '14 at 8:17

emphasis on git checkout origin/test

Discussions

Correct way of checkout and build from a branch
My team use a simple model with Git. Master branch is the latest development and is considered as unstable. For RC (ReleaseCandidate) we make a new branch for every release and use the version as branchname. Like “2018.09”. So the buildscript checkout and build master every morning. More on finalbuilder.com
🌐 finalbuilder.com
3
0
September 12, 2018
What is the difference between git checkout on a branch vs git checkout on a commit?

One's a road one's a mile marker.

More on reddit.com
🌐 r/learnprogramming
6
5
August 24, 2019
`git checkout -b` vs `git switch -c` to create new branch
Doesnt matter. Pick the one you prefer. If you want a slightly longer answer: Checkout is overloaded: It switches branches: git co foo It creates branches git co -b foo It can restore files: git co master /path/to/file It can reset the worktree: git co -p And maybe more things, which is why they introduced git switch and git restore. But both are fine to use. I only use checkout. You can use switch, or not. Pick any. Who cares, it's your shell. More on reddit.com
🌐 r/git
78
117
December 24, 2025
'git checkout master' command not working. Can't figure out the issue
Are you sure that you have a 'master' branch? You can run git branch -v to see available branches. I lot of servers now use main instead of master for default branch. More on reddit.com
🌐 r/git
25
0
September 5, 2022
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git checkout
Git Checkout | Atlassian Git Tutorial
The difference between the two commands is that clone works to fetch code from a remote repository, alternatively checkout works to switch between versions of code already on the local system.
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-checkout-branch
Git Checkout Branch - GeeksforGeeks
February 26, 2026 - ... By using this you will see if there are uncommitted changes or if your working directory is clean. ... Use the git checkout command followed by the branch name to switch to the desired branch.
🌐
GitKraken
gitkraken.com › home › learn › git checkout
Git Checkout - Checkout Branches, Commits, & Tags | Learn Git
March 26, 2026 - This will also show you which branch you currently have checked out. Next, you will run the Git checkout command followed by the name of the local branch you wish to switch over to.
Find elsewhere
🌐
Git Tower
git-tower.com › learn › git faq › git checkout & switch: how to change branches
Git Checkout & Switch: How to Change Branches | Learn Version Control with Git
5 days ago - # These two are equivalent: $ git checkout -b new-feature $ git switch -c new-feature # These two are equivalent: $ git checkout -f other-branch $ git switch --discard-changes other-branch
🌐
CloudBees
cloudbees.com › blog › git-checkout-remote-branch
How To Git Checkout a Remote Branch
March 23, 2021 - More recent versions of Git allow you to simply run git checkout v2-wip directly. Git looks for a local branch, and if it doesn't find one, it assumes you're talking about a remote branch of the same name.
🌐
Atlassian Support
support.atlassian.com › atlassian support › bitbucket › resources › set up and work on repositories in bitbucket cloud › branch or fork your repository
Check out a branch | Bitbucket Cloud | Atlassian Support
May 14, 2020 - If you plan to use branches a lot ... devoted to the DVCS you are using (Git or Mercurial). When you checkout a branch, you should already have a local clone of the parent repository. The Bitbucket interface gives you the basic command for checking out a branch....
🌐
LogRocket
blog.logrocket.com › home › how to check out a remote branch in git: a step-by-step guide
How to check out a remote branch in Git: A step-by-step guide - LogRocket Blog
March 13, 2025 - This means a duplicate branch is created locally and does not keep track of the remote branch. If you run git pull, there will be conflicts. To avoid that unnecessary headache, git fetch first, then git checkout -b <branch name>
🌐
GitHub
gist.github.com › markSci5 › 5916003
Git checkout remote branch · GitHub
git fetch will fetch all the remote branches, which you can verify with git branch -r (or git branch -rv), and as long as you don't have an existing branch with the name you want, you can just switch directly to it with git checkout <branch>. All ...
🌐
Finalbuilder
finalbuilder.com › discussion
Correct way of checkout and build from a branch - VSoft Technologies Forums
September 12, 2018 - My team use a simple model with Git. Master branch is the latest development and is considered as unstable. For RC (ReleaseCandidate) we make a new branch for every release and use the version as branchname. Like “2018.09”. So the buildscript checkout and build master every morning.
🌐
InMotion Hosting
inmotionhosting.com › inmotion hosting home › support › website › git › git checkout command – how to switch to branches and commits
Git Checkout Command - How To Switch To Branches and Commits | InMotion Hosting
February 20, 2025 - The “checkout” command in Git, or git checkout in practice, has many different uses throughout the life of a Git project. However, it is primarily used as a way of “checking out” different versions of your project. For example, if you want to look at a branch or a commit from some time ...
🌐
Go Packages
pkg.go.dev › github.com › royeo › git-checkout-branch
git-checkout-branch command - github.com/royeo/git-checkout-branch - Go Packages
Usage: git checkout-branch [flags] Flags: -a, --all List both remote-tracking branches and local branches -r, --remotes List the remote-tracking branches -n, --number Set the number of branches displayed in the list (default 10) --hide-help Hide the help information
🌐
W3Schools
w3schools.com › git › git_branch.asp
Git Branch
checkout is the command used to check out a branch. Moving us from the current branch, to the one specified at the end of the command: git checkout hello-world-images Switched to branch 'hello-world-images'
🌐
IONOS
ionos.com › digital guide › websites › web development › git checkout
How to switch branches with Git Checkout - IONOS
November 4, 2022 - Git Checkout’s simplest function is switching from one existing branch to another as described above. You can use the Git Branch command to find out which branches are currently available if you’re not sure.
🌐
BoldGrid
boldgrid.com › support › wordpress-tutorials › how-to-checkout-a-branch-using-github
How to Checkout a branch in a Github repository
March 12, 2020 - After confirming that you have available branches to move to, its time to checkout the branch you want to work on. Since we want to make changes without disturbing the master branch, let’s checkout the dev branch. To switch to our dev branch we need to enter the command ‘git checkout’ ...
🌐
Ahtisham Hasan Khan
iahtisham.com › blog › mastering-the-git-checkout-command
Mastering the Git Checkout Command - Git Branching and Undoing Changes
July 4, 2024 - This command gracefully undoes the last commit while preserving the changes in your working directory, giving you the flexibility to make further adjustments. To move to a specific commit in Git without creating a new branch, use the git checkout command followed by the commit hash:
🌐
Quora
quora.com › What-does-a-checkout-do-in-git
What does a checkout do in git? - Quora
Answer: What does a checkout do in git? The [code ]git checkout[/code] command lets you navigate between the branches created by [code ]git branch[/code]. Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all n...