gitting better

183
Gitting Better

Upload: ali-servet-donmez

Post on 14-Jul-2015

76 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Gitting better

Gitting Better

Page 2: Gitting better

Gitting Betterkind

a

Page 3: Gitting better

Hats Off

Gitting Better

Hello, World!

Overview

Page 4: Gitting better

Hats Off

Gitting Better

Hello, World!

Overview

Gitting Better

Hello, World!

Page 5: Gitting better
Page 6: Gitting better

What Git is ?

Page 7: Gitting better

What Git is ?NOT

Page 8: Gitting better

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

Page 9: Gitting better

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

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

Page 10: Gitting better

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

Page 11: Gitting better

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

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

Page 12: Gitting better

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

Page 13: Gitting better

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

Page 14: Gitting better

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.

Page 15: Gitting better

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.

Page 16: Gitting better

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!

Page 17: Gitting better

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.

Page 18: Gitting better

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.

Page 19: Gitting better

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!

Page 20: Gitting better

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.

Page 21: Gitting better

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.

Page 22: Gitting better

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.

Page 23: Gitting better

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.

Page 24: Gitting better

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.

Page 25: Gitting better

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.

Page 26: Gitting better

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.

Page 27: Gitting better

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.

Page 28: Gitting better

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.

Page 29: Gitting better

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.

Page 30: Gitting better

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

show the command line versions of the functions.

Page 31: Gitting better

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

show the command line versions of the functions.

Page 32: Gitting better

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

Page 33: Gitting better

help config

init

add

rm

mv

status

commit

logdiff

show

branch

checkout

mergetag

clone

fetch

pullpush

remote

stash

clean

reset

rebase

bisect

grep

reflog

Page 34: Gitting better

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

Page 35: Gitting better

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

Page 36: Gitting better

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

Page 37: Gitting better

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

Page 38: Gitting better

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!

Page 39: Gitting better

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

Page 40: Gitting better

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

Page 41: Gitting better

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

Page 42: Gitting better

Getting Startedhelp & config

Page 43: Gitting better

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

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

Page 44: Gitting better

demo

Page 45: Gitting better

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

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

Page 46: Gitting better

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

default!

Page 47: Gitting better

$ git config --global user.name “John Doe”$ git config --global user.email “[email protected]

Page 48: Gitting better

demo

Page 49: Gitting better

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

Page 50: Gitting better
Page 51: Gitting better

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

Page 52: Gitting better

Repositor

y

Page 53: Gitting better
Page 54: Gitting better
Page 55: Gitting better
Page 56: Gitting better

$ git init

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

Page 57: Gitting better

$ git init

Page 58: Gitting better

$ git init

Page 59: Gitting better

$ git initRepo

sitory

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

Page 60: Gitting better

$ git init

$ git init

Page 61: Gitting better

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

Page 62: Gitting better
Page 63: Gitting better
Page 64: Gitting better

demo

Page 65: Gitting better

$ git add <files>

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

Page 66: Gitting better

$ git add <files>

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

Page 67: Gitting better

$ git add <files>

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

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

Page 68: Gitting better

Now Pay Attention!The Three States

Page 69: Gitting better

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.

Page 70: Gitting better

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

Page 71: Gitting better

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.

Page 72: Gitting better

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.

Page 73: Gitting better

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.

Page 74: Gitting better

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.

Page 75: Gitting better

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.

Page 76: Gitting better

Staging Area

Page 77: Gitting better

Staging Area

Stage files

Page 78: Gitting better

Staging Area

Stage files

Commit

Page 79: Gitting better

Working Copy Staging Area Repository

git add$

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

<files>

Page 80: Gitting better

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

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

git rm$ <files>

Working Copy Staging Area Repository

Page 81: Gitting better

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

git mv$ <source> <destination>

Working Copy Staging Area Repository

Page 82: Gitting better

demo

Page 83: Gitting better

$ git status

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

Page 84: Gitting better

demo

Page 85: Gitting better

$ git commit

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

ry

Page 86: Gitting better
Page 87: Gitting better

Staging Area

Page 88: Gitting better

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

Staging Area

Page 89: Gitting better

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

Staging Area

Stage files

Page 90: Gitting better

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

Staging Area

Stage files

initial comm

it

Commit

Page 91: Gitting better

demo

Page 92: Gitting better

History Commandslog, diff & show

Page 93: Gitting better

History Commandslog, diff & show

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

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

Page 94: Gitting better
Page 95: Gitting better

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <[email protected]>Date: Fri Jun 21 06:00:26 2013 -0700

Page 96: Gitting better

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <[email protected]>Date: Fri Jun 21 06:00:26 2013 -0700

Page 97: Gitting better

SHA: 1a410efbd13591db07496601ebc7a059dd55cfe9Author: John Doe <[email protected]>Date: Fri Jun 21 06:00:26 2013 -0700

Page 98: Gitting better

human-readable-name

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

Page 99: Gitting better

tagsbranches

remotes

human-readable-name

Page 100: Gitting better

HEAD

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

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

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

Page 101: Gitting better

something

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

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

something-else

Page 102: Gitting better

something

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

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

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

Page 103: Gitting better

History Commandslog, diff & show

Page 104: Gitting better

$ git log

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

Page 105: Gitting better

$ git diff

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

Page 106: Gitting better

$ git show

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

Page 107: Gitting better

demo

Page 108: Gitting better

Branching Commandsbranch, checkout, merge & tag

Page 109: Gitting better

without branches

Page 110: Gitting better
Page 111: Gitting better

HEAD

Page 112: Gitting better

HEAD

Page 113: Gitting better

HEAD

Page 114: Gitting better

HEAD

Page 115: Gitting better

HEAD

Page 116: Gitting better

HEAD

Page 117: Gitting better

HEAD

Page 118: Gitting better

HEAD

Page 119: Gitting better

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

Page 120: Gitting better
Page 121: Gitting better

HEADmaster

Page 122: Gitting better

HEADmaster

Page 123: Gitting better

HEADmaster

Page 124: Gitting better

HEADmaster

Page 125: Gitting better

HEADmaster

Page 126: Gitting better

HEADmaster

Page 127: Gitting better

HEADmaster

Page 128: Gitting better

HEADmaster

Page 129: Gitting better

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

day)

Page 130: Gitting better
Page 131: Gitting better

HEADmaster

Page 132: Gitting better

HEADmaster

Page 133: Gitting better

HEADmaster

Page 134: Gitting better

HEADanything

Renamed

Page 135: Gitting better

HEADanything

Page 136: Gitting better

HEADanything cool-feature

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

branch!

Page 137: Gitting better

HEAD

anything

cool-feature

Page 138: Gitting better

HEAD

anything

cool-feature

Page 139: Gitting better

HEADanything

cool-feature

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

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

Page 140: Gitting better

HEAD anything

cool-feature

Page 141: Gitting better

HEAD anything cool-feature

Page 142: Gitting better

HEADanything cool-feature

Page 143: Gitting better

HEAD

anything

cool-feature

Merged

Page 144: Gitting better

anything

cool-feature

HEAD

Page 145: Gitting better

anything cool-featureHEAD

Page 146: Gitting better

anything mainHEAD

Page 147: Gitting better

anything

main

HEAD

Page 148: Gitting better

anything

main HEAD

Page 149: Gitting better

v0.0.1

anything

main HEAD

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

Page 150: Gitting better

anything main HEAD

v0.0.1

Page 151: Gitting better

anything main HEAD

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

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

Page 152: Gitting better

$ git branch

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

Page 153: Gitting better

$ git checkout

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

Page 154: Gitting better

$ git merge

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

Page 155: Gitting better

$ git tag

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

r

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

Page 156: Gitting better

demo

Page 157: Gitting better

Remote Commandsremote, fetch, pull, push & clone

Page 158: Gitting better
Page 159: Gitting better
Page 160: Gitting better

Matteo

Page 161: Gitting better

Matteo

Fabio

Page 162: Gitting better

Fabio

Matteo

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

http://https://

Page 163: Gitting better
Page 164: Gitting better

WTF?!

Page 165: Gitting better
Page 166: Gitting better
Page 167: Gitting better
Page 168: Gitting better
Page 169: Gitting better

$ git remote

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

Page 170: Gitting better

$ git fetch

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

Page 171: Gitting better

$ git pull

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

Page 172: Gitting better

$ git pull

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

Page 173: Gitting better

$ git push

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

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

Page 174: Gitting better

$ git clone

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

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

Page 175: Gitting better

demo

Page 176: Gitting better
Page 177: Gitting better

Matteo

Fabio

Page 178: Gitting better

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

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

Page 179: Gitting better
Page 180: Gitting better
Page 181: Gitting better

demo

Page 182: Gitting better

References

• git-scm.com

• gitref.org

Page 183: Gitting better

Useful Resources

• try.github.io

• learn.github.com

• teach.github.com

• training.github.com