Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To work on a branch that exists on a remote, create a local branch that tracks its remote-tracking reference. For example, run git switch -c topic --track origin/topic. This creates local topic, switches to it, and sets origin/topic as its upstream.

What “checking out a remote branch” means

In everyday Git usage, “check out a remote branch” usually means creating a local branch from the remote branch’s latest locally known state, then switching to that local branch. The local branch is where you can make commits; its upstream records which remote-tracking branch it corresponds to.

origin/topic and topic are different references. origin/topic is a remote-tracking reference stored locally under refs/remotes/, representing the state of the remote branch as last observed. The local branch topic is stored under refs/heads/. origin is only a conventional remote name, not a special Git keyword. See the Pro Git chapter on remote branches.

Create a local branch that tracks the remote

Use an explicit remote-qualified command when you want predictable branch naming and upstream setup:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git switch -c topic --track origin/topic

This creates and switches to local topic and configures it to track origin/topic. The equivalent command with the older, broader checkout command is:

git checkout -b topic --track origin/topic

Git documents these branch-creation and tracking options in the git switch and git checkout manuals. Use either command for ordinary development; switch is focused specifically on changing branches, while checkout remains supported and can also operate on files.

When Git can infer the remote branch

If local topic does not exist and exactly one remote has a matching remote-tracking branch, Git can infer that you mean to create a local branch tracking it. In that case, either of these may be enough:

git switch topic
git checkout topic

This short-name guessing behavior is enabled by default and can be disabled with --no-guess; its default can also be configured. The explicit --track form avoids relying on inference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the remote when branch names collide

If more than one remote has a branch called topic, Git may not know which one you intend. Name the remote explicitly in the tracking reference:

git switch -c topic --track upstream/topic

Alternatively, checkout.defaultRemote can designate a preferred remote for disambiguation. Explicitly naming the remote is clearest when you need a particular branch, especially when remotes such as origin and upstream both contain the same short name. The setting and inference behavior are documented in the switch and checkout manuals.

Inspect a remote-tracking branch without creating a local branch

For a quick inspection or a throwaway experiment, you can switch directly to the remote-tracking reference:

git switch --detach origin/topic

This checks out the referenced commit with HEAD detached. You are not on a named local branch, so commits made in this state are not attached to a branch in the usual way. If you want to keep developing, create a tracking branch instead with git switch -c topic --track origin/topic. The Pro Git remote-branches chapter also distinguishes working on a new local branch from checking out a remote-tracking reference directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If the remote branch is not visible

A remote-tracking reference is a local record of a branch observed on a remote; it is not the remote branch itself. If the reference you expect is unavailable, confirm the remote name and branch name, and update your local view of the remote before trying the explicit tracking command. The command examples above require a matching remote-tracking reference, such as origin/topic, to exist locally.

What happens to uncommitted changes when you switch?

Switching branches updates the index and working tree to match the target. Git permits a switch when it can preserve your local changes, but aborts if switching would overwrite them. Review or save changes before switching if you are unsure what the target branch will replace.

--discard-changes overrides that protection: it restores the index and working tree to match the target branch. Use it only when you intend to discard those local differences. The behavior is described in the git switch manual.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.