• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Actual Wizard

Actual Wizard

Great Content From Actual Wizards

  • Blogging
  • Programming
  • Social Media
  • Marketing
You are here: Home / Programming

How to use Git to Checkout a Remote Branch

October 11, 2020 by Kevin Marszalek

Checking out a remote branch can be surprisingly difficult due to Git’s complexity.

This tutorial will explain how to do that step by step.

Clone the Remote Repository if you have not already.

Example: This clones the WordPress Repository on GitHub.

git clone https://github.com/WordPress/WordPress

Retrieving the Original Remote Repository

To ensure that your local copy of the repository matches the remote one, use the fetch command to retrieve the origin.

Example:

git fetch origin

List the Remote Branches Available to Checkout

You now want to list out the remote branches available for you to checkout with the branch command, using the -r option to list out the remote branches.

Example:

git branch -r

Tip: By default, Git will send the output to a program named “Less” that can be used to edit text. To exit Less and return to the command shell, press the q keyboard.

You can also add the –no-pager option, immediately after ‘git’, before the other options in the Git command line.

This will pipe the output back to the console instead of using Less to process the page of data.

Example:

git --no-pager branch -r

Check Out the Remote Branch for the First Time

Here’s where things get tricky.

Most likely, you want to clone the remote branch and switch to it without being in the detached head state.

To do that, you will need to use the -b option and supply the branch’s path from the origin.

Example:

git checkout -b 4.0-branch origin/4.0-branch

The output will let you know that the command has been executed successfully.

Branch '4.0-branch' set up to track remote branch '4.0-branch' from 'origin'.
Switched to a new branch '4.0-branch'

You can verify that you are on the correct branch with the following command:

git branch --show-current

Which should output:

4.0-branch

Checking out a remote Branch That You’ve Previously Checked out Before

If you have already checked out the remote branch, the command to switch to it is much simpler.

Example:

git checkout 5.0-branch

Which Should Output:

Switched to branch '5.0-branch'
Your branch is up to date with 'origin/5.0-branch'.

Filed Under: Programming

Read More From Actual Wizard

  • Understanding the Different Parts of an Email Address
    An email address has four parts; the recipient name, the @ symbol, the domain name, and the top-level domain. …
  • How to Get the Last Element of an Array in JavaScript
    There are a number of different ways to get the last element of an array in JavaScript. Below we will explore …
  • How to use document.write() in JavaScript
    How to use document.write() in JavaScript The document.write() function is commonly used when testing simple …
  • How to Open a New Tab with JavaScript
    Opening a new browser window in a new tab can be done easily in JavaScript. Modern web browsers provide a …

Primary Sidebar

More posts from this section

  • How to Get the Last Element of an Array in JavaScript
  • How to use document.write() in JavaScript
  • How to Open a New Tab with JavaScript
  • PX to EM Converter – Online CSS Font Size Tool
  • How to Hide the URL Address in the Browser Status Bar
  • Heart Symbol HTML Code with Examples
  • HTML Trademark Symbol Code Example
  • Prevent a Phone Number from Wrapping to a New Line in CSS HTML
  • Html Tutorial Hello World Example with Code
  • Force a File to Download Instead of Opening it in a Browser with HTML

Copyright © 2025 ActualWizard.com

  • About
  • Terms of Service
  • Privacy Policy
  • Cookie Policy