gitting better

Post on 14-Jul-2015

76 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Gitting Better

Gitting Betterkind

a

Hats Off

Gitting Better

Hello, World!

Overview

Hats Off

Gitting Better

Hello, World!

Overview

Gitting Better

Hello, World!

What Git is ?

What Git is ?NOT

Git is not...... a convenient backup solution for your source code

Git is not...... a convenient backup solution for your source code

but����������� ������������������  it����������� ������������������  is����������� ������������������  pretty����������� ������������������  good����������� ������������������  at����������� ������������������  it!����������� ������������������  :D

Git is not...... another pain in the ass you have to deal with

Git is not...... another pain in the ass you have to deal with

but����������� ������������������  it����������� ������������������  is����������� ������������������  pretty����������� ������������������  good����������� ������������������  at����������� ������������������  it!����������� ������������������  :(

What Git is...... a distributed version control andsource code management system.

What Git is...... a distributed version control andsource code management system.

First off, Git is a version control system,a simple command line tool for keeping a history on

the state of your source code projects.

You use it as you might use something likeSubversion, CVS or Perforce.

First off, Git is a version control system,a simple command line tool for keeping a history on

the state of your source code projects.

You use it as you might use something likeSubversion, CVS or Perforce.

First off, Git is a version control system,a simple command line tool for keeping a history on

the state of your source code projects.

You use it as you might use something likeSubversion, CVS or Perforce.

“cli”

snapshots,����������� ������������������  not����������� ������������������  diffs!

Git allows groups of people to work on the same documents (often code) at the same time, and without

stepping on each other’s toes.

Git allows groups of people to work on the same documents (often code) at the same time, and without

stepping on each other’s toes.

Git allows groups of people to work on the same documents (often code) at the same time, and without

stepping on each other’s toes.

NO����������� ������������������  MUTEX,����������� ������������������  YAY!

You tell it to track files in your project andperiodically commit the state of the project when

you want a saved point.

You can share that history withother developers for collaboration,

merge between their work and yours, andcompare or revert to previous versions of

the project or individual files.

You tell it to track files in your project andperiodically commit the state of the project when

you want a saved point.

You can share that history withother developers for collaboration,

merge between their work and yours, andcompare or revert to previous versions of

the project or individual files.

Git is fully distributed, which means that it canwork almost entirely offline.

In contrast to VCS tools like Perforce or Subversion, Git does nearly all of its operations without needing a

network connection, including history viewing, difference viewing and commiting.

This means that Git is very fast compared to other systems partially due to the fact that none of these operations has any dependency on network latency.

Git is fully distributed, which means that it canwork almost entirely offline.

In contrast to VCS tools like Perforce or Subversion, Git does nearly all of its operations without needing a

network connection, including history viewing, difference viewing and commiting.

This means that Git is very fast compared to other systems partially due to the fact that none of these operations has any dependency on network latency.

Git is also very space efficient.

It is even smaller than the Subversion checkout,which is pretty amazing, considering that

the Git clone contains the entire history of the project— every version of every file back to the first commit,

whereas the Subversion checkout is just the last version of the project.

Git is also very space efficient.

It is even smaller than the Subversion checkout,which is pretty amazing, considering that

the Git clone contains the entire history of the project— every version of every file back to the first commit,

whereas the Subversion checkout is just the last version of the project.

Probably the most compelling feature of Git isGits branching model.

Instead of the popular VCS branching method ofsimply cloning into a separate directory for a branch,

Git lets you switch between branches ina single working directory.

Creating and switching between branches isnearly instant, not all of your branches need to

be shared, and it’s easy tostash partially completed work.

Probably the most compelling feature of Git isGits branching model.

Instead of the popular VCS branching method ofsimply cloning into a separate directory for a branch,

Git lets you switch between branches ina single working directory.

Creating and switching between branches isnearly instant, not all of your branches need to

be shared, and it’s easy tostash partially completed work.

Instead of only having branches formajor development line departures,

Git developers routinely create, merge and destroy multiple branches a week, or even per day.

Often each feature or bug you are working on can have its own branch, merged in only when it is complete. This

model allows you to experiment quickly, easily and safely - without having to go through hoops to get back to where you where. It enables and encourages a non-

linear development cycle, where you can work on multiple lines of thought in parallel without them

stepping on each other.

Instead of only having branches formajor development line departures,

Git developers routinely create, merge and destroy multiple branches a week, or even per day.

Often each feature or bug you are working on can have its own branch, merged in only when it is complete. This

model allows you to experiment quickly, easily and safely - without having to go through hoops to get back to where you where. It enables and encourages a non-

linear development cycle, where you can work on multiple lines of thought in parallel without them

stepping on each other.

As it is primarily a command line tool,most of the examples in this course will

show the command line versions of the functions.

As it is primarily a command line tool,most of the examples in this course will

show the command line versions of the functions.

As it is primarily a command line tool,most of the examples in this course will

show the command line versions of the functions.

on����������� ������������������  a����������� ������������������  Mac����������� ������������������  :

D

help config

init

add

rm

mv

status

commit

logdiff

show

branch

checkout

mergetag

clone

fetch

pullpush

remote

stash

clean

reset

rebase

bisect

grep

reflog

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

Getting����������� ������������������  Started

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

Basic����������� ������������������  stuff

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

History

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

Branching!

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

Remote����������� ������������������  (HUH?)

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

grep

reflog

advanced����������� ������������������  stuff

help

config

init

add

rm

mv

status

commit

log

diff

show

branchcheckout

merge

tag

clone

fetch

pull

push

remote

stash

clean

reset

rebase

bisect

reflog

Getting Startedhelp & config

$ git help <verb>$ git <verb> --help

Display����������� ������������������  “HELP!”����������� ������������������  information����������� ������������������  about����������� ������������������  Git

demo

$ git config --system <key> <value>$ git config --global <key> <value>$ git config --local <key> <value>

Get����������� ������������������  and����������� ������������������  set����������� ������������������  repository����������� ������������������  or����������� ������������������  global����������� ������������������  options

$ git config --system <key> <value>$ git config --global <key> <value>$ git config --local <key> <value>

default!

$ git config --global user.name “John Doe”$ git config --global user.email “johndoe@example.com”

demo

Basic Commandsinit, add, rm, mv, status & commit

Working����������� ������������������  Copy

Repositor

y

$ git init

Create����������� ������������������  an����������� ������������������  empty����������� ������������������  git����������� ������������������  repository

$ git init

$ git init

$ git initRepo

sitory

Working����������� ������������������  Copy

$ git init

$ git init

Central����������� ������������������  Repository

demo

$ git add <files>

Add����������� ������������������  new����������� ������������������  or����������� ������������������  modified����������� ������������������  files����������� ������������������  to����������� ������������������  the����������� ������������������  staging����������� ������������������  area

$ git add <files>

Add����������� ������������������  new����������� ������������������  or����������� ������������������  modified����������� ������������������  files����������� ������������������  to����������� ������������������  the����������� ������������������  staging����������� ������������������  area

$ git add <files>

Add����������� ������������������  new����������� ������������������  or����������� ������������������  modified����������� ������������������  files����������� ������������������  to����������� ������������������  the����������� ������������������  staging����������� ������������������  area(a.k.a.����������� ������������������  “index”����������� ������������������  

or����������� ������������������  “cache”)

Now Pay Attention!The Three States

This is the main thing to remember about Git ifyou want the rest of your

learning process to go smoothly.

Git has three main states that your files can reside in: committed, modified, and staged.

This is the main thing to remember about Git ifyou want the rest of your

learning process to go smoothly.

Git has three main states that your files can reside in: committed, modified, and staged.

1 2 3

Committed means that the data issafely stored in your local database.

Modified means that you have changed the file buthave not committed it to your database yet.

Staged means that you have marked amodified file in its current version togo into your next commit snapshot.

Committed means that the data issafely stored in your local database.

Modified means that you have changed the file buthave not committed it to your database yet.

Staged means that you have marked amodified file in its current version togo into your next commit snapshot.

Committed means that the data issafely stored in your local database.

Modified means that you have changed the file buthave not committed it to your database yet.

Staged means that you have marked amodified file in its current version togo into your next commit snapshot.

Committed means that the data issafely stored in your local database.

Modified means that you have changed the file buthave not committed it to your database yet.

Staged means that you have marked amodified file in its current version togo into your next commit snapshot.

Committed means that the data issafely stored in your local database.

Modified means that you have changed the file buthave not committed it to your database yet.

Staged means that you have marked amodified file in its current version togo into your next commit snapshot.

Staging Area

Staging Area

Stage files

Staging Area

Stage files

Commit

Working Copy Staging Area Repository

git add$

Add����������� ������������������  new����������� ������������������  or����������� ������������������  modified����������� ������������������  files����������� ������������������  to����������� ������������������  the����������� ������������������  staging����������� ������������������  area

<files>

Remove����������� ������������������  files����������� ������������������  from����������� ������������������  the����������� ������������������  working����������� ������������������  directory

and����������� ������������������  staging����������� ������������������  area

git rm$ <files>

Working Copy Staging Area Repository

Move����������� ������������������  or����������� ������������������  rename����������� ������������������  a����������� ������������������  file,����������� ������������������  or����������� ������������������  a����������� ������������������  directory

git mv$ <source> <destination>

Working Copy Staging Area Repository

demo

$ git status

Show����������� ������������������  the����������� ������������������  status����������� ������������������  of����������� ������������������  the����������� ������������������  working����������� ������������������  directoryand����������� ������������������  staging����������� ������������������  area

demo

$ git commit

Record����������� ������������������  changes����������� ������������������  to����������� ������������������  the����������� ������������������  reposito

ry

Staging Area

$ echo “Hello, World!” >> hello.txt

Staging Area

$ echo “Hello, World!” >> hello.txt$ git add hello.txt

Staging Area

Stage files

$ echo “Hello, World!” >> hello.txt$ git add hello.txt$ git commit --message “Initial commit.”

Staging Area

Stage files

initial comm

it

Commit

demo

History Commandslog, diff & show

History Commandslog, diff & show

Before����������� ������������������  to����������� ������������������  get����������� ������������������  there,

let’s����������� ������������������  talk����������� ������������������  about����������� ������������������  references����������� ������������������  (or����������� ������������������  “refs”)

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <johndoe@example.com>Date: Fri Jun 21 06:00:26 2013 -0700

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <johndoe@example.com>Date: Fri Jun 21 06:00:26 2013 -0700

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <johndoe@example.com>Date: Fri Jun 21 06:00:26 2013 -0700

human-readable-name

wouldn’t����������� ������������������  that����������� ������������������  be����������� ������������������  awesome?

tagsbranches

remotes

human-readable-name

HEAD

symbolic����������� ������������������  reference����������� ������������������  to

where����������� ������������������  you����������� ������������������  are����������� ������������������  pointing����������� ������������������  at

right����������� ������������������  now

something

A����������� ������������������  tree����������� ������������������  is����������� ������������������  “lost”����������� ������������������  without����������� ������������������  a

symbolic����������� ������������������  reference����������� ������������������  to����������� ������������������  it!!!

something-else

something

A����������� ������������������  tree����������� ������������������  is����������� ������������������  “lost”����������� ������������������  without����������� ������������������  a

symbolic����������� ������������������  reference����������� ������������������  to����������� ������������������  it!!!

This����������� ������������������  is����������� ������������������  not����������� ������������������  true����������� ������������������  actually,but����������� ������������������  that’s����������� ������������������  advanced����������� ������������������  stuff

History Commandslog, diff & show

$ git log

Show����������� ������������������  the����������� ������������������  commit����������� ������������������  history����������� ������������������  log

$ git diff

Show����������� ������������������  changes����������� ������������������  between����������� ������������������  commits,����������� ������������������  commit����������� ������������������  and����������� ������������������  working����������� ������������������  tree,����������� ������������������  etc

$ git show

Show����������� ������������������  information����������� ������������������  about����������� ������������������  commits,����������� ������������������  tags����������� ������������������  or����������� ������������������  files

demo

Branching Commandsbranch, checkout, merge & tag

without branches

HEAD

HEAD

HEAD

HEAD

HEAD

HEAD

HEAD

HEAD

without branchesthinking����������� ������������������  about

HEADmaster

HEADmaster

HEADmaster

HEADmaster

HEADmaster

HEADmaster

HEADmaster

HEADmaster

with branches(a����������� ������������������  typical����������� ������������������  Git����������� ������������������  

day)

HEADmaster

HEADmaster

HEADmaster

HEADanything

Renamed

HEADanything

HEADanything cool-feature

A����������� ������������������  brand����������� ������������������  new����������� ������������������  

branch!

HEAD

anything

cool-feature

HEAD

anything

cool-feature

HEADanything

cool-feature

Switch����������� ������������������  to����������� ������������������  

another����������� ������������������  branch...

HEAD anything

cool-feature

HEAD anything cool-feature

HEADanything cool-feature

HEAD

anything

cool-feature

Merged

anything

cool-feature

HEAD

anything cool-featureHEAD

anything mainHEAD

anything

main

HEAD

anything

main HEAD

v0.0.1

anything

main HEAD

Tag����������� ������������������  things.

anything main HEAD

v0.0.1

anything main HEAD

Pretty����������� ������������������  much

anything����������� ������������������  you����������� ������������������  wantv0.0.1

$ git branch

List,����������� ������������������  create,����������� ������������������  or����������� ������������������  delete����������� ������������������  branches

$ git checkout

Switch����������� ������������������  the����������� ������������������  active����������� ������������������  branch����������� ������������������  to����������� ������������������  another����������� ������������������  branch

$ git merge

Join����������� ������������������  two����������� ������������������  or����������� ������������������  more����������� ������������������  developmenthistories����������� ������������������  (branches)����������� ������������������  together

$ git tag

Create,����������� ������������������  list,����������� ������������������  delete,����������� ������������������  sign����������� ������������������  o

r

verify����������� ������������������  a����������� ������������������  tag����������� ������������������  object

demo

Remote Commandsremote, fetch, pull, push & clone

Matteo

Matteo

Fabio

Fabio

Matteo

file://ssh://git://

http://https://

WTF?!

$ git remote

View����������� ������������������  and����������� ������������������  manage����������� ������������������  a����������� ������������������  set����������� ������������������  of����������� ������������������  remote����������� ������������������  repositories

$ git fetch

Download����������� ������������������  data,����������� ������������������  tags����������� ������������������  and����������� ������������������  branches����������� ������������������  froma����������� ������������������  remote����������� ������������������  repository

$ git pull

Fetch����������� ������������������  from����������� ������������������  and����������� ������������������  merge����������� ������������������  with����������� ������������������  another����������� ������������������  repository����������� ������������������  or����������� ������������������  a����������� ������������������  local����������� ������������������  branch

$ git pull

Fetch����������� ������������������  from����������� ������������������  and����������� ������������������  merge����������� ������������������  with����������� ������������������  another����������� ������������������  repository����������� ������������������  or����������� ������������������  a����������� ������������������  local����������� ������������������  branch

$ git push

Upload����������� ������������������  data,����������� ������������������  tags����������� ������������������  and����������� ������������������  branches����������� ������������������  to

a����������� ������������������  remote����������� ������������������  repository

$ git clone

Clone����������� ������������������  a����������� ������������������  remote����������� ������������������  repository����������� ������������������  into

a����������� ������������������  new����������� ������������������  directory

demo

Matteo

Fabio

A����������� ������������������  teammate����������� ������������������  that

never����������� ������������������  sleeps!

demo

References

• git-scm.com

• gitref.org

Useful Resources

• try.github.io

• learn.github.com

• teach.github.com

• training.github.com

top related