cheking out, b-switch
Asked by Stefan Mueller:

Hallo,

I'm bit confused by the checkout dialog. In my understanding *Checkout New Branch* will create a new branch and checks it out as explained in the Tutorial [Using Branches git branch, git checkout -b](https://www.atlassian.com/git/tutorials/using-branches). That is neccessary when I e.g. want to create a branch to add a hotfix.

But when I use Sourcetree's dialog it seem more that it only add a remote branch to my local working copy and make it the active branch. It updates the files in the working directory to match the version stored in that branch.

It doesn't matter on which tab I click it shows me only existing branches. The only difference is that *Checkout New Branch*doesn't show the branches what triggers the warning shown at ther very end of this post.

I found some more explaination on [git SCM - git-checkout - Switch](https://git-scm.com/docs/git-checkout) and [git SCM - 3.2 Git Branching](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging) but it rather top ups confusion than making me understand.

Do you mind the explain the *Checkout* in some more detail to me?

In addtion, what effect does the following option have?   
*Local branch should track remote branch*   

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/6124iEF75D1B0F8C10117/image-size/large?v=1.0&px=-1 "image.png")

![image.png](/t5/image/serverpage/image-id/6125i06DF6EEC7DF632EC/image-size/large?v=v2&px=999 "image.png")

![image.png](/t5/image/serverpage/image-id/6123iDC3E434EE05B46DD/image-size/large?v=v2&px=999 "image.png")


Answers:
author: minnsey
body: Hi  
The 'Branch' command runs the follow git commands

\`\`\`  
git branch (name) (commit)  
git checkount (name)

\`\`\`

where the (commit) is optional. This creates a new branch at the commit or the current HEAD. It then checks out the new branch  

The 'Checkout New Branch' functionality runs:

\`\`\`  
git checkout -b (name) (remote)

\`\`\`

Optionally tracking or not. This creates a new local Branch based on the HEAD of the named remote branch  

In both circumstances you end up with a new local branch, but the 'Create New Branch' allows that to be created from an arbitrary remote branch, where as 'Branch' functionality works against the current working copy branch.  

<br />

the track/no Track option determines whether the local branch is associated with the remote branch or just created from it. If you don't track then you can't push your new branch to the remote host until you explicitly set that relationship up at push time.

comments: author: Stefan Mueller
body: [@minnsey](/t5/user/viewprofilepage/user-id/502201) thx for your reply but I have to admit that I still have some problems to understanding git speech.

When I clone a repo I have only a local copy of the newest version (latest uploaded/pushed file set/commit) of that repo content. In addition I have a local copy of the repo history.

When I want to switch to another commit I double click on it what will download it to my local copy. In my understanding that what happens when I do *Checkout new branch*.

When I want to changed to an already copied commit I double click it also but this time I do *Checkout existing branch.*

When I don't thick Track, git doesn't know where to upload/push my commit to within the repos commit/branch tree, correct?

If I want to create an entirely new branch I follow [Create and push a branch to the remote repository (Git)](https://confluence.atlassian.com/get-started-with-sourcetree/create-and-push-a-branch-to-the-remote-repository-git-847359118.html).


author: Stefan Mueller
body: [@minnsey](/t5/user/viewprofilepage/user-id/502201)[](https://community.atlassian.com/t5/user/viewprofilepage/user-id/502201), is my answer understandable or shell a revise ma last answer?


author: minnsey
body: *When I clone a repo I have only a local copy of the newest version (latest uploaded/pushed file set/commit) of that repo content. In addition I have a local copy of the repo history.*

That is correct  

*When I want to switch to another commit I double click on it what will download it to my local copy. In my understanding that what happens when I do Checkout new branch.*   

When you double click on commit that is NOT the HEAD (the end or last commit) of a branch you will checkout that version of the code but with what is called a detached HEAD, it is not a working branch and there is no where to commit and push changes to.  

If you right click on a commit that is NOT the HEAD of a branch you can create a new Branch from that commit.  

If you double click on a commit that IS the HEAD of a branch, if it is a branch you have opened before and all of the commits have already been Fetched to you r local machine you will just be asked to switch to the branch. If you have never opened that branch or you are trying to open it from commits you have not yet fetched down to you machine you will be asked to potentially open a new copy of that branch

<br />

*If I want to create an entirely new branch I follow [Create and push a branch to the remote repository (Git)](https://confluence.atlassian.com/get-started-with-sourcetree/create-and-push-a-branch-to-the-remote-repository-git-847359118.html?_ga=2.103961792.1739694769.1506945250-326791178.1478388529).*correct.

<br />

<br />

<br />

I hope this helps.


author: Stefan Mueller
body: a bit :)  
it seems I still struggling with the expression HEAD. In my understanding it was just a pointer to a commit but is seems to be more.  
`HEAD` is **the "tip" of the current branch** as well explained [here](https://stackoverflow.com/questions/2304087/what-is-head-in-git). That means HEAD contains all files of the latest 'uploaded/pushed file set/commit', correct?

Still trying to understand the rest, will come back to you later.


Tags: check-out