Fetch a remote branch in Git

David Y.

The Problem

In my Git repository, how do I fetch a branch from a remote to start working on locally? There is no equivalently named branch in my local repository.

The Solution

We can do this using git fetch to retrieve the remote branch and git switch to work on it locally. First, fetch the remote branch:

git fetch remote-branch

Then switch to it:

git switch remote-branch

Under the hood, this command will create a local branch named remote-branch, which tracks the version of remote-branch on the repository’s remote, and check it out. We can then make commits, push them, and pull others’ commits from this branch as usual.

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.