Git

Fetching a Remote Branch in Git

Fetching a Remote Branch in Git

The Problem

How can you fetch a branch from a remote repository in Git and start working on it locally when there is no equivalent branch in your local repository?

The Solution

You can fetch the remote branch and switch to it using git fetch and git switch. Here’s how:

First, fetch the remote branch:

git fetch origin remote-branch

Then, switch to the fetched branch:

git switch remote-branch

Under the hood, this command will create a local branch named remote-branch, which tracks the remote branch of the same name, and check it out. This allows you to make commits, push changes, and pull updates from this branch as usual.

Suggested Articles

Leave a Reply

Your email address will not be published. Required fields are marked *