How to Checkout Remote Branch in Git?
Last Updated :
13 May, 2024
When collaborating on projects using Git, you'll often need to switch between different versions of the codebase stored in remote repositories. These versions are managed through branches. To work on a specific version (branch) hosted remotely ( on GitHub), you need to check it out in your local Git repository.
Approach 1: Detaching the HEAD
This approach checks out the remote branch directly without creating a corresponding local branch. Your local HEAD pointer is attached to the remote branch.
Step 1: Fetch the Remote Branch (if necessary) :
If your local repository doesn't have information about the remote branch, use `git fetch` to download information:
git fetch origin # Fetches all branches from the default remote "origin"
To fetch only a specific remote branch:
git fetch origin <branch_name> # Replace `<branch_name>` with the actual branch name
Step 2: Checkout the Remote Branch
Use the following command, specifying the remote branch name prefixed with `origin/`:
git checkout origin/<branch_name>
Example: To checkout the remote branch `feature/new-design` from the remote repository `origin`:
git checkout origin/feature/new-design

Approach 2: Creating a Local Tracking Branch (Recommended)
This method creates a new local branch that tracks the remote branch. This allows you to work on the remote branch locally and easily synchronize your changes with the remote repository.
Step 1: Fetch the Remote Branch (if necessary) - Same as previous approach
Step 2: Checkout and Create a Local Branch
Use the `git checkout -b` command to create a new local branch named `<local_branch_name>` that tracks the remote branch `<branch_name>`.
git checkout -b <local_branch_name> origin/<branch_name>
Example: Create a local branch named `my-feature` to track the remote branch `feature/new-design`:
git checkout -b my-feature origin/feature/new-design

Step 3: Verification
After checking out the remote branch using either approach, use `git branch` to verify:
git branch
The currently checked-out branch will have an asterisk (*) next to its name.

Choosing the Right Approach
- Detaching the HEAD can be useful in specific cases, like temporary work on a remote branch without affecting your local branches. However, it's generally less common.
- Creating a local tracking branch is the recommended approach for most situations. It keeps your local repository organized and simplifies synchronization with the remote repository.
Additional Considerations
- If a local branch with the same name as the remote branch already exists, `git checkout` might behave differently. It's recommended to either delete the local branch beforehand or use `git checkout -b` to create a new tracking branch.
- Detached HEAD doesn't have a local branch to commit to. You'll need to use `git checkout <branch_name>` to switch to a local branch before committing your changes.
Similar Reads
How to Checkout Remote Branch in Git?
When collaborating on projects using Git, you'll often need to switch between different versions of the codebase stored in remote repositories. These versions are managed through branches. To work on a specific version (branch) hosted remotely ( on GitHub), you need to check it out in your local Git
3 min read
How to Checkout New Banch in Git?
Git provides powerful features for managing code changes, collaborating with teammates, and organizing development workflows. One essential task in Git is checking out new branches, which allows developers to work on isolated features, fix bugs, or experiment with changes without affecting the main
2 min read
How To Delete Remote Branch in Git?
Git is an important tool in the process of application development and is used widely in the software industry by developers to maintain the codebase. Using this developers are able to organize their codebase and manage the version history of their project. Now, as a developer, you need to know how
1 min read
How To Fetch Remote Branches in Git ?
Git provides a powerful version control system that allows developers to collaborate efficiently on projects. Over time, however, a repository can have local and remote branches. Local branches are created locally and only exist on local machines and the remote branches exist on the remote repositor
3 min read
How to Check Branch in Git?
In Git, branches are independent lines of development that allow you to work on features or fixes without affecting the main codebase. Checking branches is important for managing project history, coordinating collaboration, and ensuring smooth development workflows. This article will walk you throug
2 min read
How to Create a Remote Git Branch?
Creating a remote Git branch allows multiple developers to work on different features or fixes simultaneously. It ensures a clean and organized workflow, enabling collaboration without affecting the main codebase. This article covers the steps to create a remote Git branch and push it to a remote re
2 min read
How to Checkout a Tag in Git?
When working with Git, checkout a tag is one of the basic operations. Tags are pointers that show certain points in the history of your project and usually indicate releases or some important stages. The purpose of checkout a tag is to make your working directory represent the repository as it was a
3 min read
How to Clone all Remote Branches in Git?
Cloning a repository is a common task when working with Git, but what if you need all the branches from a remote repository? By default, Git clones only the default branch (usually 'master' or 'main'). However, you may need access to all remote branches in many scenarios. This article will guide you
2 min read
How to List Remote Branches in Git?
Git is a powerful version control system that allows developers to collaborate on projects, maintain code history, and manage multiple lines of development through branching. One common task when working with Git is to list all branches in a remote repository. This article will guide you through the
3 min read
How to Rename Branch in Git?
Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consisten
1 min read