Getting Git

1,117 views

Published on

A presentation on the basics of Git, for April of the 2011 Webuquerque talks series.

http://webuquerque.com/Events/Getting-Git.php

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,117
On SlideShare
0
From Embeds
0
Number of Embeds
273
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Getting Git

    1. 1. Getting
GitWebuquerque,
April
2011
    2. 2. Who
am
I?Brian
Arnold(Upper
left)Software
Engineer
for
SitePen,
Inc.JavaScript
fanaticTechnology
evangelist
    3. 3. Who
are
you?A
developer/designer
whos
lost
work
beforeA
freelancer
who
needs
to
manage
a
wide
variety
of
projectsSomeone
to
heckle
me,
asking
me
if
I
used
jQuery
to
make
this
presentation
    4. 4. Version
Control! What
is
it?
Why
do
I
care?
    5. 5. Version
ControlProper
definition:Version
control
is
a
means
of
managing
a
set
of
files,
typically
code
or
markup
of
some
sort,
managed
as
repositories
of
codeVarieties
of
version
control
systems: Ad‐hoc,
Centralized,
Distributed A
wide
variety
of
choices
    6. 6. Ad‐hoc This
works...
 sort
of Easy
to
lose
 work Hard
to
 manage
    7. 7. Centralized
VCSRequires
a
central
server
(and
therefore
typically
network
access
to
said
server)Clients
(thatd
be
you)
typically
get
a
copy
of
the
latest
version
of
the
repositorys
contentsDepending
on
implementation,
files
may
be
checked
out
or
locked
while
working
on
them
    8. 8. Centralized
VCSCVS
(1990)Microsoft
Visual
SourceSafe
(1994)Subversion
(2000)
    9. 9. Distributed
VCSClient
typically
makes
a
copy
of
the
entire
repository
to
their
systemMost
actions
are
local
to
your
system,
not
network‐basedPossible
to
have
a
centralized
shared
repository
to
facilitate
multi‐user
work
    10. 10. Distributed
VCSGit
(2005)Mercurial
(2005)Bazaar
(2007)
    11. 11. Choose
Wisely!Centralized
systems
can
be
simpler
to
manageDistributed
much
easier
to
use
on
smaller
scaleThink
about
your
needs
‐
dont
just
bash
something
because
its
not
cool
    12. 12. So
then...Why
am
I
talking
about
Git?
    13. 13. A
Solid
ChoiceGit
is
a
distributed
version
control
system
(DVCS)Immensely
popular,
used
to
manage
a
ton
of
popular
open
source
projectsFantastic
educational
materials
    14. 14. Whats
special?Stores
snapshots
of
files(NOT
differences)Nearly
every
operation
is
local(no
server
needed!)Written
to
be
strong
against
corruption
of
data
while
being
highly
performant
    15. 15. Fscking
Git,
how
 does
it
work??Git
is
somewhat
like
a
self‐contained
file
system,
with
three
distinct
areas: Working
directory Staging
area Repository
    16. 16. Working
Directory Your
main
working
area
for
files Just
a
directory Has
the
most
recent
version
of
the
 code
    17. 17. Staging
AreaInternal
to
GitHas
copies
of
files
that
are
being
set
up
to
be
pushed
into
the
repositoryFiles
can
be
added
and
removed
before
being
committed
into
the
repository
    18. 18. RepositoryThe
.git
directoryAll
of
Gits
metadata,
objects,
and
database
are
stored
in
here,
after
theyve
been
staged
and
committedHere
there
be
Dragons
(dont
alter
files
in
this
directory
directly)Often
referred
to
as
a
Repo
    19. 19. Getting
Git! By
which
I
mean,installing
it
in
some
fashion, not
comprehension, thats
later
    20. 20. http://bit.ly/SetUpGitWill send you to help.github.com for your OS
    21. 21. Global
ConfigThe
dollar
sign
in
their
instructions
represents
the
prompt
‐
dont
actually
type
it
outThe
steps
walk
you
through
setting
up
some
configuration
that
is
GitHub‐specificThe
global
config
is
not
GitHub‐specificDo
set
your
user.name
and
user.email
configuration
pieces
before
you
start
up
a
repository,
as
per
instruction
    22. 22. Global
Config
    23. 23. Getting
Git!Okay,
now
were
talking
comprehension
    24. 24. GoalsHow
to
start
using
Git
as
an
individualComfort
with
creating
your
own
repo(Hopefully
some)
comfort
with
branching
and
mergingFeeling
excited
for
Git!
    25. 25. git
initSetting
up
your
repo
    26. 26. Starting
Point
    27. 27. Starting
Point
    28. 28. git
init
    29. 29. git
init
    30. 30. git
initThats
itNo,
really,
thats
itYou
now
have
a
Git
repository!
    31. 31. git
statusChecking
in
on
your
repo
    32. 32. git
statusA
useful
command
to
check
the
status
of
your
current
workspace,
as
well
as
staging
areaGives
you
useful
information
as
to
actions
you
can
takeWell
be
using
this
command
often
throughout
the
presentation
    33. 33. git
status
    34. 34. git
addSetting
the
stage
for
your
repo
    35. 35. git
addAdd
files
to
the
Staging
Area
(prep
for
being
put
in
the
repository)Marks
files
to
be
tracked
by
Git
when
they
are
staged
for
the
first
timeWill
work
recursively
through
directoriesOften
people
run
`git
add
.`
to
set
up
all
files
    36. 36. git
add
    37. 37. HOLD
UP!What
if
I
dont
want
all
the
files?
    38. 38. .gitignoreA
special
file
to
GitPut
at
the
root
of
your
working
directoryList
files
and
patterns
you
want
to
ignore
    39. 39. .gitconfig
    40. 40. .gitconfig
    41. 41. .gitconfig
    42. 42. .gitconfig
    43. 43. .gitconfig
    44. 44. git
diff What
changed?
    45. 45. git
diffShows
you
changes
in
your
files
that
have
not
been
stagedIf
a
change
is
staged,
it
wont
show
up
in
a
git
diff
unless
you
use
the
‐‐cached
option
after
the
command
    46. 46. git
diff
    47. 47. git
commitActually
putting
files into
the
repository
    48. 48. git
commitMoves
files
from
the
Staging
Area
into
the
RepositoryAccepts
a
Commit
Message Messages
are
important! Succinctly
describe
the
changes
 youre
committing
    49. 49. git
commitUse
the
‐m
command
to
add
a
message:git
commit
‐m
"My
message"You
can
skip
adding,
and
just
commit
all
tracked
files
with
‐a:git
commit
‐am
"Several
changes"
    50. 50. Message
about
 messagesPlease,
please
write
good
commit
messagesImportant
for
looking
back
in
the
history
of
your
repositoryMakes
it
easy
for
the
moron
whos
stuck
maintaining
your
work
later(Youre
often
that
moron,
so
be
nice
to
yourself)
    51. 51. git
commit
    52. 52. WOO!WE
HAVE
CODE
SAFELY
STORED!
    53. 53. ...So...
now
what?
    54. 54. Keep
doing
it!The
most
basic
and
standard
Git
workflow Work
on
your
files Choose
which
ones
to
commit
with
 git
add Properly
put
them
in
the
repo
with
 git
commit
    55. 55. Time
passesLike
sands
through
the
hourglass
    56. 56. git
logLooking
back
    57. 57. git
logA
simple,
straight‐forward
command
with
a
lot
of
power
to
review
what
youve
done
with
GitTakes
a
few
options
to
display
information
in
a
variety
of
ways
    58. 58. git
log
    59. 59. EXCITING! Well,
okay,
not.Lets
look
at
a
real
example.
    60. 60. git
log
    61. 61. git
logSome
parameters
that
can
be
used: ‐p
:
shows
the
difference ‐#
:
limits
results
to
last
#
logs ‐‐pretty
:
Can
change
format
of
 output ‐‐graph
:
Can
draw
branch
graphs
    62. 62. git
log
‐p
    63. 63. git
log
‐2
    64. 64. git
log
‐‐pretty=oneline
    65. 65. git
log
‐‐pretty=oneline
‐‐graph
    66. 66. git
logThere
are
tons
of
ways
to
look
at
your
dataThis
command
is
part
of
why
good
commit
messages
are
importantWith
poor
messages,
your
log
can
wind
up
worthless
    67. 67. Branching!But
first,
some
details
about
Git
that
 well
need
to
understand
branching. Would
this
be
a
branch... about
branches?
#rimshot Ill
be
here
all
night!
    68. 68. What
is
a
commit? A
container
of
 metadata Commit Has
a
pointer
to
 the
directory
 snapshot Has
zero
or
more
 pointers
to
 parent
commits Snapshot
    69. 69. What
is
a
commit? C1 Each
time
you
 commit,
the
new
 commit
records
 which
one
came
 before
it
    70. 70. What
is
a
commit? C1 C2 Each
time
you
 commit,
the
new
 commit
records
 which
one
came
 before
it C3
    71. 71. What
is
a
branch? master A
branch
is
 nothing
more
than
 a
pointer
to
a
 commit In
fact,
you
 always
have
one
 C3 branch
at
first: master
    72. 72. Callback!
    73. 73. Another
visualizationCourtesy of progit.org
    74. 74. git
branchManaging
your
branches
    75. 75. git
branchWith
no
additional
options,
it
will
list
all
of
your
branches,
starring
the
one
youre
currently
on
    76. 76. git
branch
    77. 77. git
branch
    78. 78. git
branchWhen
provided
with
a
word
after
the
command,
it
creates
a
branch
with
that
name
    79. 79. git
branch
testing
    80. 80. git
branch
testing
    81. 81. git
branchSo,
how
does
Git
know
what
branch
youre
on?Git
maintains
another
pointer,
called
"HEAD",
which
points
at
the
branch
youre
onThis
makes
more
sense
with
a
graphic,
so
lets
see
one
    82. 82. git
branch
testing
    83. 83. git
checkoutHow
to
move
from
branch
to
branch
    84. 84. git
checkoutTo
move
from
one
branch
to
another,
simply
run
`git
checkout
branchname`
where
branchname
is
the
branch
you
want
to
move
toIf
you
want
to
create
a
branch
at
the
time
of
checkout,
run
it
with
the
‐b
option:git
checkout
‐b
newbranch
    85. 85. git
checkout
testing
    86. 86. git
checkout
testing
    87. 87. git
checkoutOnce
youve
switched
to
another
branch,
you
can
start
working
like
you
normally
had
beenUse
`git
add`
and
`git
commit`
like
before
    88. 88. Work
like
normal
    89. 89. Whats
happening?
    90. 90. Moving
aroundYou
can
work
on
multiple
branches
in
tandemDont
be
afraid
to
branch
‐
as
theyre
just
pointers,
the
overhead
for
using
branches
is
very
low
    91. 91. Moving
around
    92. 92. Moving
around
    93. 93. git
mergeGetting
the
code
back
together
    94. 94. Starting
point
    95. 95. Starting
point
    96. 96. URGENT!!!
    97. 97. Your
Repos
State
    98. 98. git
mergeWhen
given
the
name
of
a
branch,
it
does
its
best
to
intelligently
sync
up
file
changesIf
possible,
it
simply
moves
pointers
forward
    99. 99. git
merge
    100. 100. git
merge
    101. 101. git
mergeIf
it
cant
just
fast
forward,
git
will
create
a
new
commit
that
points
back
at
the
merge
basesGit
will
do
its
best
to
intelligently
merge
the
two
commits,
and
it
generally
does
the
right
thingSometimes,
though,
we
dont
    102. 102. Making
conflict
    103. 103. git
merge
    104. 104. git
merge
    105. 105. git
mergeIn
order
to
fix
a
conflict,
open
your
file
and
look
for
the
<<<<<<
lineIt
will
show
you
what
conflicted
‐
clean
up,
save,
and
git
add
the
file
to
mark
the
conflict
as
resolved
    106. 106. git
merge
    107. 107. git
merge
    108. 108. git
merge
    109. 109. git
merge
    110. 110. Looking
back
    111. 111. HomeworkBecause
we
all
love
homework!
    112. 112. HomeworkGo
install
Git
on
your
system:http://bit.ly/SetUpGitSet
up
a
GitHub
account
while
youre
thereGo
read
http://progit.org/book/Try
Git
out
on
your
next
project!
    113. 113. Questions!Like
we
have
time
for
questions. This
is
slide
110!
    114. 114. Thank
you!Talk
to
me:brianarn@gmail.com@brianarn
on
Twitter/GitHubRate
me:http://spkr8.com/t/7087View
this
presentations
repo:https://github.com/brianarn/GettingGit

    ×