This document uses a metaphor of time travel and alternate timelines to explain how version control with Git can be used to solve problems. It tells a story of an astronaut on a ship who needs to patch an oxygen leak and jetpack. By committing changes to "save points" and creating branches to experiment on, the astronaut is able to patch the issues multiple times by traveling back to previous states using Git commands like checkout, merge, and rebase. It then provides explanations of key Git concepts like repositories, commits, branches, merging, rebasing, forking, cloning, pushing, pulling and resolving conflicts.
16. git checkout -b get_patch_kit
Then, you can create
an alternate timeline
and jump to it.
17. Now, in that alternate
timeline, you can start
experimenting:
To patch the air leak, you
have to get the patch kit
outside the ship. So let’s
see if you can just jump
outside and grab it
without the spacesuit.
44. git checkout -b repair_tanks_v2git checkout -b repair_tanks_v2
To fix the rest of the
leak, you have to
go back in time to
before you picked
up the patch kit …
45. git checkout -b repair_tanks_v2git checkout going_outside
… create a new
branch from the
main timeline,
where the patch kit
has not yet been
used …
57. … and resolve it by
changing one of
the patches to
remove the
overlap.
58. git commit -m “patch conflict resolved”
Now you can
commit the final
merge which serves
as the save point
for the finished
patch. And that’s it!
Problem solved!
66. git checkout -b air_supply
Create a new
branch called
“air_supply” …
67. git commit -m “making love out of
nothing at all”
… commit a new
save point with our
70% full air tank …
68. git rebase master
… and rewrite
history by rebasing
the new save point
to the top of our
current timeline.
69. Using Git, we’ve used the same patch kit
three times to fix the jetpack and the air leak
(twice), and borrowed an air supply from
the past to top off our tanks.
78. CONFLICT
Changes have taken place in
both both timelines after they
were split apart. You must
decide what change to keep
and what change to discard.
79. git rebase
Rewrite history by tacking the
events of one timeline onto
another as if they were always
there.
80. git rebase
Rewrite history by tacking the
events of one timeline onto
another as if they were always
there.
82. git clone
Make a duplicate copy of an
external universe and place it
in the current one.
Empty repo
83. git clone
Make a duplicate copy of an
external universe and place it
in the current one.
Clone
84. git push
Physically push your commits
to another repository
(typically Github)
Push
Local
Remote
85. git fetch
Grab the current version of an
external timeline and open it.
Local
Remote
Fetch
86. git pull
Grab the current version of an
external timeline and merge it
with the current timeline.
Local
Remote
Pull
87. DETACHED HEAD
Before using the time machine,
changes were made without
being committed, thereby
detaching them. Create a new
timeline to restore reality.
Uncommitted
change
88. DETACHED HEAD
Before using the time machine,
changes were made without
being committed, thereby
detaching them. Create a new
timeline to restore reality.
Checkout
89. DETACHED HEAD
Before using the time machine,
changes were made without
being committed, thereby
detaching them. Create a new
timeline to restore reality.
Detached
head
90. DETACHED HEAD
Before using the time machine,
changes were made without
being committed, thereby
detaching them. Create a new
timeline to restore reality.
Fix with
new branch
91. Don’t let the command line deter you.
There are better options!