Checkout

satya - 4/11/2018, 9:56:23 AM

What does checkout do in git?

What does checkout do in git?

Search for: What does checkout do in git?

satya - 4/11/2018, 10:00:05 AM

Here is that question on SOF

Here is that question on SOF

satya - 4/11/2018, 10:16:31 AM

Here is commits and branches

satya - 4/11/2018, 10:17:41 AM

A checkout

satya - 4/11/2018, 10:19:15 AM

The SOF ref says about checkout a branch

Sets the HEAD to the latest commit point of that branch

Updates the working directory with that code from that HEAD of that branch

Any future commits will advance that commit tree branch

satya - 4/16/2018, 10:17:31 AM

Reference doc for checkout

Reference doc for checkout

satya - 4/16/2018, 10:20:58 AM

Keeps local files

Local mods to files are kept

new files are kept

satya - 4/16/2018, 10:30:07 AM

Detached HEAD

By default checkout moves the HEAD to the head commit of the branch specified

You can also use checkout to move HEAD to a previous commit

When a commit happens on that intermediate commit, the HEAD will diverge without a new branch name

So this HEAD has no branch to speak off

Such is a detached HEAD

satya - 4/16/2018, 10:30:32 AM

You can do 2 things then

Tag that detached head

Or give a new branch name to that detached head

satya - 4/16/2018, 10:41:06 AM

Fetch

Downloads all information from a remote repo

Brings all the references (like the names of branches and commits)

Also brings down the code

** but will not merge the code with local branches **

satya - 4/16/2018, 10:42:18 AM

Appears....

checkout is local. is it?

Fetch is remote..

satya - 4/16/2018, 10:45:01 AM

Checkout will not merge, that is not its goal...

It should not...

because it is switching the branch we work on

You want to work on a different thing, and not what you are working on now. A merge will defeat that

satya - 4/16/2018, 10:46:11 AM

This is a good introduction to working with remotes

This is a good introduction to working with remotes

satya - 4/16/2018, 10:50:28 AM

Git Pull

Does a fetch on a remote branch (if tracking is set)

Also merge that with the current branch

satya - 4/16/2018, 10:50:53 AM

Git clone

Sets up the local master branch to track the remote master

satya - 4/16/2018, 10:51:18 AM

So

Running git pull generally fetches data from the server you originally cloned from and automatically tries to merge it into the code you?re currently working on.

satya - 4/16/2018, 11:30:03 AM

A fetch only downloads but not make a remote branch available for checkout

fetch brings down the remotes branches and their code

will not merge

You have to merge yourself

You cannot switch to that remote branch without setting up a local tracking branch

The remote branch stays read only (I think..)

satya - 4/16/2018, 11:30:42 AM

Checkout and a Tracking branch

Checking out a local branch from a remote-tracking branch automatically creates what is called a ?tracking branch? (and the branch it tracks is called an ?upstream branch?). Tracking branches are local branches that have a direct relationship to a remote branch. If you?re on a tracking branch and type git pull, Git automatically knows which server to fetch from and which branch to merge in.

satya - 4/16/2018, 11:32:49 AM

Here is a tracking checkout syntax

$ git checkout --track origin/serverfix

Branch serverfix set up to track remote branch serverfix from origin.

Switched to a new branch 'serverfix'

satya - 4/16/2018, 11:36:40 AM

Here is what happens

Create a local branch to match the name of the server branch

Fetch that branch down

Update the working directory to match the semantics of checkout of any other local branch

satya - 4/16/2018, 11:37:38 AM

A pull now on that tracked branch will merge the local work with remote work

A pull now on that tracked branch will merge the local work with remote work