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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:54:18+00:00 2026-05-25T12:54:18+00:00

I have cloned a Git repository and I would like to switch to a

  • 0

I have cloned a Git repository and I would like to switch to a particular branch from the following list (e.g., branch1, branch2, branch3).

Should I have to say git fetch origin branch2?

How do I know that I have switched to this particular branch on my local repository?

How do I switch to say ‘branch3’ from ‘branch2’?

  • 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-25T12:54:18+00:00Added an answer on May 25, 2026 at 12:54 pm

    Recent versions of git have enough DWIM (“Do What I Mean!”) logic to understand you just doing:

    git checkout branch1
    

    … in that situtation. That will work if there is no local branch called branch1, and there’s only one remote-tracking branch that ends with branch1 – in that case it’s equivalent to the longer:

    git checkout --track -b branch1 origin/branch1
    

    … which should work in every circumstance.


    I realize that I missed answering some of your later questions. git stores the state of the branches from the origin repository in so-called “remote-tracking branches” – these are the ones that look like origin/master, origin/branch1, origin/branch2, etc. If you want to update all of these from origin just use:

    git fetch origin
    

    To see all of your remote-tracking branches, you can use:

    git branch -r
    

    The meaning of the full command I quoted above:

    git checkout --track -b branch1 origin/branch1
    

    … is:

    • create and switch to a new branch called branch1 (the checkout -b branch1 bit)
    • start it at origin/branch1 (i.e. base it on the lastest cached state of branch1 from origin)
    • and mark origin/branch1 as being “upstream” of branch1 in your git config (the --track bit, although that’s actually implied if the start point is a remote-tracking branch)
    • 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 have a git repository on github. I would like to migrate the master
I have git repository A and git repository B, and I would like to
I have an existing Git repository on my local machine. I would like to
I have a git repository which tracks an svn repository. I cloned it using
I have a repository which I have already cloned from Subversion. I've been doing
My company uses Subversion; I prefer Git. I have cloned the Subversion repository on
I would like to access (clone/push/pull) a private (via ssh) git repository while behind
I have recently extracted a few subdirectories from a shared git repository with git
Newbie with git here. I have a Remote Repository, cloned on my PC. It's

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.