Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:15:25+00:00 2026-06-02T14:15:25+00:00

I cloned a Git repository containing many branches. However, git branch only shows one:

  • 0

I cloned a Git repository containing many branches. However, git branch only shows one:

$ git branch
* master

How would I pull all the branches locally so when I do git branch, it shows the following?

$ git branch
* master
* staging
* etc...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:15:27+00:00Added an answer on June 2, 2026 at 2:15 pm

    TL;DR answer

    git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
    git fetch --all
    git pull --all
    

    (It seems that pull fetches all branches from all remotes, but I always fetch first just to be sure.)

    Run the first command only if there are remote branches on the server that aren’t tracked by your local branches.

    Complete answer

    You can fetch all branches from all remotes like this:

    git fetch --all
    

    It’s basically a power move.

    fetch updates local copies of remote branches so this is always safe for your local branches BUT:

    1. fetch will not update local branches (which track remote branches); if you want to update your local branches you still need to pull every branch.

    2. fetch will not create local branches (which track remote branches), you have to do this manually. If you want to list all remote branches:
      git branch -a

    To update local branches which track remote branches:

    git pull --all
    

    However, this can be still insufficient. It will work only for your local branches which track remote branches. To track all remote branches execute this oneliner BEFORE git pull --all:

    git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
    

    P.S. AFAIK git fetch --all and git remote update are equivalent.



    Kamil Szot’s comment, which folks have found useful.

    I had to use:

    for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
    

    because your code created local branches named origin/branchname and
    I was getting "refname ‘origin/branchname’ is ambiguous whenever I
    referred to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a remote git repository and I have cloned one branch git clone
I cloned something from git repository, and switched branch git clone ssh://11.21.3.12:23211/dir1/dir2 dir git
I cloned a git repository from GitHub, made some changes and some commits; I
I just cloned the git repository for the SBJson framework and imported the source
I've created a bare git repository (Core), cloned from a pre-existing repo (Production) using
I have a git repository which tracks an svn repository. I cloned it using
Some repository clones I have allow me to do this: % git pull %
cloning an svn repository into git is easy with git-svn. However, I need to
I've cloned the Official GCC git repository, which includes a full GCC development history,
Is it possible to clone a git repository which has more than one revisions?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.