cheking out, b-switch

Stefan Mueller September 13, 2017

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. 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 and git SCM - 3.2 Git Branching 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 

image.png

 

image.png

1 answer

0 votes
minnsey
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2017

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.


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.

Stefan Mueller September 27, 2017

@minnsey 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).

Stefan Mueller October 2, 2017

@minnsey, is my answer understandable or shell a revise ma last answer? 

minnsey
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2017

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


If I want to create an entirely new branch I follow Create and push a branch to the remote repository (Git).

correct.




I hope this helps.

Stefan Mueller October 4, 2017

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. 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. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events