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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:45:29+00:00 2026-06-01T13:45:29+00:00

Does anybody know the difference between these two commands to switch and track a

  • 0

Does anybody know the difference between these two commands to switch and track a remote branch?

git checkout -b branch origin/branch
git checkout --track origin/branch

I think both keep track of the remote branch so I can push my changes to the branch on origin, right?

Are there any practical differences?

  • 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-01T13:45:30+00:00Added an answer on June 1, 2026 at 1:45 pm

    The two commands have the same effect (thanks to Robert Siemer’s answer for pointing it out).

    The practical difference comes when using a local branch named differently:

    • git checkout -b mybranch origin/abranch will create mybranch and track origin/abranch
    • git checkout --track origin/abranch will only create ‘abranch‘, not a branch with a different name.

    (That is, as commented by Sebastian Graf, if the local branch did not exist already.
    If it did, you would need git checkout -B abranch origin/abranch)


    Note: with Git 2.23 (Q3 2019), that would use the new command git switch:

    git switch -c <branch> --track <remote>/<branch>
    

    If the branch exists in multiple remotes and one of them is named by the checkout.defaultRemote configuration variable, we’ll use that one for the purposes of disambiguation, even if the <branch> isn’t unique across all remotes.
    Set it to e.g. checkout.defaultRemote=origin to always checkout remote branches from there if <branch> is ambiguous but exists on the ‘origin’ remote.

    Here, ‘-c‘ is the new ‘-b‘.


    First, some background: Tracking means that a local branch has its upstream set to a remote branch:

    # git config branch.<branch-name>.remote origin
    # git config branch.<branch-name>.merge refs/heads/branch
    

    git checkout -b branch origin/branch will:

    • create/reset branch to the point referenced by origin/branch.
    • create the branch branch (with git branch) and track the remote tracking branch origin/branch.

    When a local branch is started off a remote-tracking branch, Git sets up the branch (specifically the branch.<name>.remote and branch.<name>.merge configuration entries) so that git pull will appropriately merge from the remote-tracking branch.
    This behavior may be changed via the global branch.autosetupmerge configuration flag. That setting can be overridden by using the --track and --no-track options, and changed later using git branch --set-upstream-to.


    And git checkout --track origin/branch will do the same as git branch --set-upstream-to):

     # or, since 1.7.0
     git branch --set-upstream upstream/branch branch
     # or, since 1.8.0 (October 2012)
     git branch --set-upstream-to upstream/branch branch
     # the short version remains the same:
     git branch -u upstream/branch branch
    

    It would also set the upstream for ‘branch‘.

    (Note: git1.8.0 will deprecate git branch --set-upstream and replace it with git branch -u|--set-upstream-to: see git1.8.0-rc1 announce)


    Having an upstream branch registered for a local branch will:

    • tell git to show the relationship between the two branches in git status and git branch -v.
    • directs git pull without arguments to pull from the upstream when the new branch is checked out.

    See “How do you make an existing git branch track a remote branch?” for more.

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

Sidebar

Related Questions

Does anybody know the memory difference between these two? Or how one would figure
I need to find the difference between two PDF files. Does anybody know of
Does anybody know the difference between Using Index and Using where; Using index in
Does anybody know what's the difference between Html.RenderAction and Html.Action ?
Does anybody know the difference between GL_UNSIGNED_SHORT_4_4_4_4 and GL_UNSIGNED_SHORT_5_6_5 data types in OpenGL ES?
Does anybody know what the main difference between session.commit() and session.flush() in SQLAlchemy is?
Does anybody know about differences in the drag-and-drop behavior between JDK1.6 and JDK1.7 ?
Does anybody know of or have a detailed list of how the BCL in
Does anybody know, how to get a list of leaf nodes in Prolog? Let's
Does anybody know of a free flash obfuscator(protector)? All I can find are commercial

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.