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 843305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:06:18+00:00 2026-05-15T06:06:18+00:00

I have a local repository cloned from a bare remote repository. The following command

  • 0

I have a local repository cloned from a bare remote repository. The following command lists al the remote repository’s branches.

$ git ls-remote <remote>

74bd3eb190edb39db04f6c0c4dbbb9e1e96bc6db    refs/remotes/test
85de54d6ae813c624b9623983e6b0a4948dae0fe    refs/remotes/trunk

I want to checkout and track that remote’s remote branch trunk. How do I do that?

Note that this is different from checking out a remote repository’s local branch.
This is how the remote repository looks like.

$ git branch -a

master
remotes/test
remotes/trunk

After running git fetch < remote > to fetch all of the remote repository’s branches, I get this output in the local repository.

$ git branch -r

repo/HEAD -> repo/master
repo/master
  • 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-05-15T06:06:18+00:00Added an answer on May 15, 2026 at 6:06 am

    You can fetch any ref from any remote (as long as the server is willing to give it to you). The key to fetching refs outside refs/heads/ is to supply full ref paths that start with refs/. If desired, you can even pull from repositories that are not configured as remotes (git fetch can take a URL instead of a remote name).

    By default, configured remotes will only fetch from the remote repository’s refs/heads/ namespace, so they will not pick up anything inside refs/remotes/. But, you could refer to a ref inside it by using a complete ref like refs/remotes/trunk (remotes/trunk might also work, but might also be ambiguous).

    If the fetched refspec does not specify a destination ref, it will be stored in the special FETCH_HEAD ref.


    Fetch a repository’s refs/remote/trunk into FETCH_HEAD and check it out as a detached HEAD:

    git fetch remote-name-or-url refs/remotes/trunk &&
    git checkout FETCH_HEAD
    

    Same, but create a named, local branch instead of using a detached HEAD:

    git fetch remote-name-or-url refs/remotes/trunk &&
    git checkout -b trunk-from-remote FETCH_HEAD
    

    Same, but directly into a local branch:

    git fetch remote-name-or-url refs/remotes/trunk:trunk-from-remote &&
    git checkout trunk-from-remote
    

    If you are working with a configured remote, you can rewrite its remote.<remote-name>.fetch configuration and add an extra entry to automate fetching from both refs/heads/ and refs/remotes/.

    # fetch branchs of remote into remote-name/heads/*
    git config remote.remote-name.fetch '+refs/heads/*:refs/remotes/remote-name/heads/*' &&
    # fetch remotes of remote into remote-name/remotes/*
    git config --add remote.remote-name.fetch '+refs/remotes/*:refs/remotes/remote-name/remotes/*'
    

    To avoid possible collisions, the above example configures fetch to store refs into disjoint namespaces (…/heads/ and …/remotes/). You can pick different names if you like. If you are sure there will be no conflicts, you can even stuff them both directly under refs/remotes/remote-name/.

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

Sidebar

Related Questions

I have a Git repository on my local machine that I cloned from my
I have cloned a Git project into a local Git repository. Then I have
With git-svn If I have cloned svn repository with all trunk, branches and tags,
I have a local repository I'm working on and its remote is hosted on
I have repository on GitHub to which I commit regularly from my local computer.
I have checked out files from my svn repository to a local project folder.
My company uses Subversion; I prefer Git. I have cloned the Subversion repository on
I have a local repository called TestRepo. I clone it with the --bare option,
I have made a bare repository (MY_LOCAL_REP) out of a public git repository hosted
I have recently extracted a few subdirectories from a shared git repository with git

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.