Git Basics
Git Basics
co
de
e
cod
The issue with Code-Sharing
The issue with Code-Sharing
Something
Home page homepage
needs
The issue with Code-Sharing
Something
Home page homepage
needs
The issue with Code-Sharing
Bro what
happened?
Something
Home page homepage
needs
The issue with Code-Sharing
Something
Home page homepage
needs
The issue with Code-Sharing
Can u like
not?
Something
Home page homepage
needs
The issue with Code-Sharing
Can u like
Can u like
✨deal with it✨
not?
Something
Home page homepage
needs
We need independent copies of the code! (so
people can work without disrupting each
other)
Something
Who homepage
broke xyz needs
i need it
rn >:(
…but that creates so many problems 😖
Hey I know you made changes in like 50 places
in that file but can you copy the changes over
one by one
Remove lines 250-280
Add 24 new lines
An hour later...
WAIT!!!!!!!!!
I NEEDED
LINES 250-280
ROLLBACK ROLLBACK
WHERE WHERE
????
The Problems
● Need independent local copies of the codebase
● Need to be able to merge different people’s changes together
● Need to keep track of versions
● Need to know which version is the most up-to-date
How do we solve these issues?
Introducing…
What does Git do?
Git tracks changes.
(How? ✨math✨)
mydoc.txt
Like corgis :D
version1 version2
mydoc.txt
I’m writing a story. I’m writing a story. I’m writing a story.
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
Doing
stuff
tim
+ I like huskies :D
e
woof.py line 27
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
Working copy
Staging & Committing
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
Staging & Committing
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
+ I like huskies :D
woof.py line 27
Staging & Committing
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
+ I like huskies :D
woof.py line 27
+ I like Andrew :D
tonythoughts.js line 24
Staging & Committing
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
Doing
stuff
tim
+ I like huskies :D
e
woof.py line 27
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
- I like cats :D
cats.py line 4
+ I like corgis :D
woof.py line 37
Doing
stuff
tim
+ I like huskies :D
e
woof.py line 27
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
- I like cats :D
cats.py line 4
+ I of.p
wo
27 :D
lik y li
e c ne
in ies
Doing
yl k
or
stuff
tim
.p us
e
gis 37
of e h
e
:D
wo I lik
+
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
- I like cats :D
cats.py line 4
dogs
Doing
stuff
tim
e
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
- I like cats :D
cats.py line 4
dogs
Doing
stuff
tim
e
d
A dde
stuff
+ I like Andrew :D
tonythoughts.js line 24
d
Starte
stuff
dogs
Commit id:
33cc
18e3
e
Doing
Message:
tim
stuff
“dogs”
d 8e33
A dde
stuff
d
Starte
stuff ca53
Uh oh, my boss is madge
tony: “vibing working on my new and improved home page ”
Uh oh, my boss is madge
tony: “vibing working on my new and improved home page ”
andrew: “can u help me fix this bug on the home page uwu”
👉👈
Uh oh, my boss is madge
tony: “vibing working on my new and improved home page ”
andrew: “can u help me fix this bug on the home page uwu”
👉👈 👉👈
Uh oh, my boss is madge
tony: “vibing working on my new and improved home page ”
😅 😅
Uh oh, my boss is madge
tony: “vibing working on my new and improved home page ”
Tony
weblab Andrew
home
tinder bug fix
page
Last
home
page
Other
stuff
Demo Branches
Demonstration
1. Creating a new branch
2. Switching between branches
Your turn! Handy commands
git branch see branches
In your new directory… git checkout [branch-name]
1. Create a new branch switch to existing branch
2. Add a couple of commits to your git checkout -b [branch-name]
branch, check the log create and checkout new branch
3. Checkout back to main, check the log
4. Add a couple of commits to main, Previous Commands
check the log git status
5. Try and draw and/or explain to your git add
partner what you think the object git commit -m
graph looks like! git log
What is happening in the object graph :0?
webtinder
main
What is happening in the object graph :0?
webtinder
main
How do we put them back together?
webtinder
main
example
merging
Follow Along
Follow along!
1. Checkout into main branch
2. Git merge [new branch name]
How do we put them back together?
webtinder
main
How do we put them back together?
.
rt of .
So
webtinder webtinder
main
main
How do we put them back together?
.
rt of .
So
webtinder webtinder
main
main
Preview
main
webtinder
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
webtinder
webtinder
main
webtinder main
main
main
👍
l l
pu
gi t
webtinder webtinder
webtinder
main main
main
+ Like corgis :D
@ Line 4