Sentry Answers>Git>

Fetch a remote branch in Git

Fetch a remote branch in Git

David Y.

The ProblemJump To Solution

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:

Click to Copy
git fetch remote-branch

Then switch to it:

Click to Copy
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.

  • ResourcesWhat is Distributed Tracing
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Loved by over 4 million developers and more than 100,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.

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