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
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

🌐
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 ...
Discussions

Why does a detached head result from `git checkout <remote>/<branch>`? And how to manage branch name collisions between multiple forks using git checkout?
I get a detached head when using the command: git checkout /, for example: git checkout prince/master //prince is the name of a remote I have setup. This puts you in detached head because you're checking out a remote-tracking branch reference. From the git book : They’re local references that you can’t move; Git moves them for you whenever you do any network communication, to make sure they accurately represent the state of the remote repository. Think of them as bookmarks, to remind you where the branches in your remote repositories were the last time you connected to them. You should create a normal local branch and set the upstream to the remote you want to track. If you do a git checkout master and master doesn't already exist, AND there is only one remote with a matching branch name, it will implicitly create the local master and set the upstream to that remote branch. If you have multiple remotes it may still do this depending on your configuration (see checkout.defaultRemote) but you can always do it manually: git checkout -b --track / I'd probably do something like: git checkout -b prince-master --track prince/master More on reddit.com
🌐 r/git
3
1
July 26, 2023
'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
How do I delete remote branches in local .git repo?
--prune option of git fetch will get rid of branches that no longer exist on a remote. E.g. git fetch --prune I use this so often I have an alias for it in .gitconfig More on reddit.com
🌐 r/git
18
12
April 21, 2024
How do I programmatically get the default remote branch name?
git ls-remote --symref origin HEAD gets the data you're after. as a compact usage example, ( set -- `git ls-remote --symref origin HEAD` test $1 = ref: && echo $2 ) More on reddit.com
🌐 r/git
9
11
October 15, 2020
🌐
CloudBees
cloudbees.com › blog › git-checkout-remote-branch
How To Git Checkout a Remote Branch
March 23, 2021 - Even though the git switch command is the preferred way of doing that since version 2.23, you can still switch branches by running git checkout <branch-name>. How can you check out remote branches in Git?
🌐
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
4 days ago - In case you are using the Tower Git client, tracking a remote branch is as easy as drag and drop: Both commands can switch and create branches, but they differ in scope: The key advantage of git switch is clarity: it only handles branch operations, reducing the risk of accidentally overwriting files when you meant to switch branches. # 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
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to · $ git checkout -b <branch> --track <remote>/<branch>
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Remote-Branches
Git - Remote Branches
However, you can set up other tracking branches if you wish — ones that track branches on other remotes, or don’t track the master branch. The simple case is the example you just saw, running git checkout -b <branch> <remote>/<branch>. This is a common enough operation that Git provides ...
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › git-checkout-remote-branch
Git Checkout Remote Branch: Step-by-Step Guide | DataCamp
September 18, 2024 - To git checkout a remote branch, you first need to fetch the latest changes from the remote repository, then you can checkout the remote branch locally using its full name (e.g., origin/branch-name).
🌐
freeCodeCamp
freecodecamp.org › news › git-checkout-remote-branch-tutorial
Git Checkout Remote Branch Tutorial
January 12, 2021 - The output of this command is the list of branches available for checkout. For the remote branches, you'll find them prefixed with remotes/origin. Note that you cannot make changes directly on a remote branch.
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-checkout-remote-branch-tutorial
How to Checkout Remote Branch in Git? - GeeksforGeeks
July 23, 2025 - You'll need to use `git checkout ... a branch from a remote repository, the first step is to fetch the latest changes from the remote server using the git fetch command....
🌐
DEV Community
dev.to › stephencweiss › git-checking-out-remote-branches-35jo
Git - Checking Out Remote Branches - DEV Community
May 10, 2019 - This is the transactional equivalent of $ git branch -f <branch> [<start point>] $ git checkout <branch> that is to say, the branch is not reset/created unless "git checkout" is successful.
🌐
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>
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git checkout
Git Checkout | Atlassian Git Tutorial
Older versions of Git require the creation of a new branch based on the remote. 1git checkout -b <remotebranch> origin/<remotebranch>
🌐
Stackify
stackify.com › git-checkout-remote-branch
Git Checkout Remote Branch: Definition and Best Practices
November 25, 2024 - Developers often split their ... command called “git checkout remote branch.” It’s just a way of referring to the action of checking out a remote branch....
🌐
Snyk
snyk.io › blog › git-checkout-remote-branch
Git checkout remote branch: how it works and when to use | Snyk Blog | Snyk
December 15, 2020 - It is good to mention that git checkout remote branch is not an actual existing command. If you want to check out a remote branch someone published, you first have to use git fetch.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how do you checkout a remote branch in git?
How do you checkout a remote Git branch? | Solutions to Git Problems
August 5, 2022 - To checkout a remote Git branch in GitKraken, you can either double-click or right-click the branch name from the left panel or central graph and select Checkout from the context menu.
🌐
Adam the Automator
adamtheautomator.com › git-checkout-remote-branch
Easily Perform Git Checkout Remote Branch [Step-by-Step]
Multiple remotes that use the same remote branch name do not exist. To perform the git checkout remote branch operation, use the git checkout command and type the name of the remote branch as seen below.
Published   October 20, 2023
🌐
DEV Community
dev.to › brianverm › git-checkout-remote-branch-how-it-works-and-when-to-use-it-ghi
Git checkout remote branch: how it works and when to use it - DEV Community
December 26, 2020 - It is good to mention that git checkout remote branch is not an actual existing command. If you want to check out a remote branch someone published, you first have to use git fetch.
🌐
Fonzi AI
fonzi.ai › blog › git-checkout-remote-branch
How to Checkout a Remote Git Branch the Right Way
August 12, 2025 - This command not only creates the new local branch but also sets it up to track the specified remote branch, so any new commits you make can be easily pushed to the remote repository. Using git checkout -b streamlines your workflow, allowing ...
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › git checkout remote branch (create local branch from origin)
Git Checkout Remote Branch (Create Local Branch from origin) | GoLinuxCloud
March 16, 2026 - Use git branch -r to list remote branches or git branch -a to see both local and remote branches available in the repository. Running git checkout origin/branch-name allows you to view the remote branch in a detached HEAD state.
🌐
Ratfactor
ratfactor.com › cards › git-remote-branch
Git - Checkout a remote branch - ratfactor
# clone the repo into a different dir $ git clone https://example.com/clown/pooper.git clown-pooper # create the local branch tracking the remote branch $ git branch new-feature origin/new-feature # switch to it $ git checkout new-feature