The answer to your question has been divided depending on whether there is one remote repository configured or various of them which are configured. This would be because the single remote case along with some of the commands can be simplified as there is less ambiguity.
Updated for Git 2.23: For older versions check the end section
With a single or multiple remotes, start by fetching from the remote repository to make sure you have all the latest changes updated and downloaded.
$ git fetch
This will help you in fetching all of the remote branches for you and you will be able to 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 reading only copies of the remote branches and to work on a branch you need to create a local branch from it which is done with the Git command switch (since Git 2.23) by giving it the name of the remote branch excluding the name of the remote as mentioned below:
$ git switch test
In this case Git is guessing that you are trying to checkout and track the remote branch with the same name. This can be can be disabled with --no-guess
However, in the case where multiple remote repositories exist, the remote repository needs to be explicitly named. To incorporate those changes, use:-
$ git fetch origin
Which is going to help you get all of the remote branches for you and with the help of the line below, can see the branches available for checkout:
$ 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
The image below shows how the fetch is different to pull and the way it operates:-
Please note that the git switch was added in Git 2.23, prior to this git checkout was used to switch branches. In order to checkout out with only a single remote repository, please use the line below:
git checkout test
However, if there there are multiple remote repositories configured it becomes a bit longer for which use:-
git checkout -b test <name of remote>/test