Checkout

What does checkout do in git?

Search for: What does checkout do in git?

Here is that question on SOF

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

Reference doc for checkout

Local mods to files are kept

new files are kept

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

Tag that detached head

Or give a new branch name to that detached head

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

checkout is local. is it?

Fetch is remote..

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

This is a good introduction to working with remotes

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

Also merge that with the current branch

Sets up the local master branch to track the remote master

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.

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

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.

$ git checkout --track origin/serverfix

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

Switched to a new branch 'serverfix'

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

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