Search code examples
gitgit-remote

Git remote branch


Today I try to track a remote branch (specifically, Mapbox-ios-sdk's 23-callouts.

So, what's the difference between the following three commands:

git checkout remotes/origin/23-callouts

git checkout -b remotes/origin/23-callouts

git checkout -b 23-callouts remotes/origin/23-callouts

The first command gives me a "(no branch)". My second command is actually a mistake I made where my third command was intended and I was surprised it goes through, and I don't know what happen there. The third command would give me what's called a "remote tracking branch", but how is that different from the second or the first? I've also seen "git checkout --track" is that the same thing as the third command?


Solution

  • You can found the answer via git help checkout & git help branch

    git checkout remotes/origin/23-callouts
    

    Try to checkout a local branch named 'remotes/origin/23-callouts', so this is not you want

    git checkout -b remotes/origin/23-callouts
    

    Try to create a new local branch named 'remotes/origin/23-callouts' base on HEAD. so this is not you want neither.

    git checkout -b 23-callouts remotes/origin/23-callouts
    

    Try to create a new local branch named '23-callouts' base on remotes branch. So it's correct

    about git checkout --track, it's almost the same, for both you got a local branch tracking with remote one, the only difference is the name of the local branch.

    git checkout --track remotes/origin/23-callouts
    

    is same as the third command. The local branch is named 23-callouts

    Via third command, you can change the name of local branch by change the param after -b