Skip to content
Fix Code Error

How to clone all remote branches in Git?

March 13, 2021 by Code Error
Posted By: Peter Coulton

I have a master and a development branch, both pushed to GitHub. I’ve cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back.

I’m sure I’m missing something obvious, but I have read the manual and I’m getting no joy at all.

Solution

First, clone a remote Git repository and cd into it:

$ git clone git://example.com/myproject
$ cd myproject

Next, look at the local branches in your repository:

$ git branch
* master

But there are other branches hiding in your repository! You can see these using the -a flag:

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

But if you want to work on that branch, you’ll need to create a local tracking branch which is done automatically by:

$ git checkout experimental

and you will see

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

Here, "new branch" simply means that the branch is taken from the index and created locally for you. As the previous line tells you, the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.

Now, if you look at your local branches, this is what you’ll see:

$ git branch
* experimental
  master

You can actually track more than one remote repository using git remote.

$ git remote add win32 git://example.com/users/joe/myproject-win32-port
$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental
  remotes/win32/master
  remotes/win32/new-widgets

At this point, things are getting pretty crazy, so run gitk to see what’s going on:

$ gitk --all &
Answered By: Anonymous

Related Articles

  • Why call git branch --unset-upstream to fixup?
  • Why do I have to "git push --set-upstream origin "?
  • Why do git fetch origin and git fetch : behave differently?
  • getting text input from a form in react.js using Refs
  • Git Using Remote Branch
  • What's the difference between git clone --mirror and…
  • Difference between git checkout --track…
  • Maven2: Missing artifact but jars are in place
  • Why does git perform fast-forward merges by default?
  • react-table has a issue with rendering in next.js
  • What is a tracking branch?
  • Git workflow and rebase vs merge questions
  • How do I clone a single branch in Git?
  • Checkout another branch when there are uncommitted…
  • What is a stack trace, and how can I use it to debug…
  • Your configuration specifies to merge with the from…
  • How to fetch all Git branches
  • Various ways to remove local Git changes
  • Unexpected end of JSON input while parsing
  • Git - Pushing code to two remotes
  • useEffect Error: Minified React error #321 (GTM…
  • Reference — What does this symbol mean in PHP?
  • What are the differences between git remote prune,…
  • What exactly does the "u" do? "git push -u origin…
  • What is "git remote add ..." and "git push origin master"?
  • How can I find the location of origin/master in git,…
  • Change a Git remote HEAD to point to something…
  • How do I delete a Git branch locally and remotely?
  • Maven parent pom vs modules pom
  • How to create the branch from specific commit in…
  • Why does Git say my master branch is "already up to…
  • Is this very likely to create a memory leak in Tomcat?
  • unable to deploy next js to azure
  • npm ERR! fetch failed status code 502
  • “tag already exists in the remote" error after…
  • Is it safe to shallow clone with --depth 1, create…
  • How to recover stashed uncommitted changes
  • Getting infinite loop after entering 2 objects to…
  • Check if pull needed in Git
  • How do I rename both a Git local and remote branch name?
  • How to generate a random string of a fixed length in Go?
  • How to solve Internal Server Error in Next.Js?
  • How does origin/HEAD get set?
  • How to pull in changes from skeleton sub-repository…
  • Setting up and using Meld as your git difftool and mergetool
  • How to track untracked content?
  • Why did my Git repo enter a detached HEAD state?
  • git lfs push to github failure on Ubuntu 18.04
  • Git push error: "origin does not appear to be a git…
  • Retrieve specific commit from a remote Git repository
  • How to remove MySQL completely with config and…
  • How do you stop tracking a remote branch in Git?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Egit rejected non-fast-forward
  • Remove tracking branches no longer on remote
  • How to upload a file in Django?
  • Git push won't do anything (everything up-to-date)
  • git remote prune – didn't show as many pruned…
  • Git fetch remote branch
  • moving committed (but not pushed) changes to a new…
  • Git submodule update
  • Merge, update, and pull Git branches without using checkouts
  • How to clone ('fork') your own personal GitHub repo…
  • git pull while not in a git directory
  • How do I make a Git commit in the past?
  • Git's famous "ERROR: Permission to .git denied to user"
  • Rename master branch for both local and remote Git…
  • How can I reconcile detached HEAD with master/origin?
  • error: pathspec 'test-branch' did not match any…
  • Detach (move) subdirectory into separate Git repository
  • In plain English, what does "git reset" do?
  • How can I delete all Git branches which have been merged?
  • Git merge master into feature branch
  • How do you get git to always pull from a specific branch?
  • Delete all local git branches
  • Git: Create a branch from unstaged/uncommitted…
  • Git push: "fatal 'origin' does not appear to be a…
  • How to download a branch with git?
  • Git merge with force overwrite
  • Why am I getting a "401 Unauthorized" error in Maven?
  • Why does C++ code for testing the Collatz conjecture…
  • Does "git fetch --tags" include "git fetch"?
  • Force "git push" to overwrite remote files
  • Rebasing remote branches in Git
  • Cleaning up old remote git branches
  • How to prune local tracking branches that do not…
  • Remove sensitive files and their commits from Git history
  • Remote branch is not showing up in "git branch -r"
  • Why is processing a sorted array faster than…
  • What is git tag, How to create tags & How to…
  • Trying to integrate Ant Design using Sass and…
  • problem with client server unix domain stream…
  • Git push rejected after feature branch rebase
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • Git: Merge a Remote branch locally
  • How can I switch to another branch in git?
  • How do I 'overwrite', rather than 'merge', a branch…
  • What is your most productive shortcut with Vim?
  • Why do I need to do `--set-upstream` all the time?
  • How do I include certain conditions in SQL Count

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to merge two arrays in JavaScript and de-duplicate items

Next Post:

Round a double to 2 decimal places

Leave a Reply Cancel reply

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

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error