Вы находитесь на странице: 1из 115

Intro to git

Andrew Kerr :: SwampHacks 2017

*Photo by Desirae Lee, courtesy of Major League


Hacking powered by Dell and Windows.
before we start...
please install git
https://git-scm.com/download
please sign up for GitHub
https://github.com/join
fyi: what you see might be
different
fyi (p2): ask questions!
what are we learning about?
who is this Andrew guy?

what is git?

why should I learn git?

where should I use git?

how do I use git?


basics

collaboration

remote

bonus: GitHub
who is @andrew?
andrew on the interwebz
https://andrewjkerr.com
https://ajk.tumblr.com
@andrewuf on Twitter/Snapchat
what is git?
Git (/t/[6]) is a version control system
(VCS) for tracking changes in
computer files and coordinating work on
those files among multiple people.
git allows us to
Track changes in files
Collaborate with others
tracking changes in git
tracking changes in git
collaborating with git
why should I learn git?
git is an industry standard.
Hackathons Companies
Open Source Classes, prob.
git is peace of mind.
Something stop working?
Accidentally deleted a file?
git is peace of mind.
Want credit for your work?
Hard drive broke?*
git is free.
No need to pay for it.
git is well supported.
Install it on Windows, macOS, *nix
git is...
Theres a lot more. But, you get the idea.
where should I use git?
Everywhere you can.
Hackathons Companies
Open Source Classes, prob.
basics of git
git terminology
repository (repo): a place for git to store
your files and your changes
It all starts with...
g it in it
Then, create some files.
git terminology
working directory: any changes you have
made that git does not know about
Add the changes to git:
g it ad d .
Add the changes to git:
g it ad d .
See this dot? This dot tells git to
look for changes in all of the files
in the directory.*
git terminology
staging area: The phase where git
knows about your changes, but havent
actually written them in stone
git terminology
commit (noun): changes to the files
tracked by git. Each commit has a
unique identifier called a commit hash.
git terminology
commit (verb): tell git to update the repo
with your changes
Tell git youre good to go:
g it com m it
git commit
Tell git youre good to go:
g it com m it -m m sg
the git flow

Init repo git init

Make changes ~ type stuff here ~

Add changes git add .

Commit changes git com m it -m m sg


demo
(extended) basics of git
See the status of your git repo:
g it statu s
git status

Before adding
(Working directory)

After adding
(Staging area)

After commiting
(Working directory)
See the diff of your changes:
g it d if f
git diff
collaborating with git
git terminology
branch: a copy of your code that you
can make changes on without affecting
others on your team
git terminology
checkout (verb): to switch to a different
branch
git terminology
master (branch): the main branch
branches

repository
m aster (branch):

text.txt
Create a new branch
g it ch eckou t -b ad d -
p ictu re
branches

repository
m aster (branch): add-picture (branch):

text.txt text.txt
branches

repository
m aster (branch): add-picture (branch):

text.txt text.txt

dog.gif
git terminology
merge (verb): to combine the changes
from a branch into another
Checkout the master branch
g it ch eckou t m aster
Merge your branch into master
g it m erg e ad d -p ictu re
branches

repository
m aster (branch): add-picture (branch):

text.txt text.txt

dog.gif dog.gif
demo
branches

repository
m aster (branch): add-picture (branch):

text.txt text.txt

dog.gif
branches
m aster (branch):

text.txt

add-audio (branch): add-picture (branch):

text.txt text.txt

music.mp3 dog.gif
branches
m aster (branch):

text.txt

music.mp3

add-audio (branch): add-picture (branch):

text.txt text.txt

music.mp3 dog.gif
branches

m aster (branch): add-picture (branch):

text.txt text.txt

music.mp3 dog.gif
g it ch eckou t m aster
g it m erg e ad d -p ictu re
branches

m aster (branch): add-picture (branch):

text.txt text.txt

music.mp3 dog.gif

dog.gif
git terminology
conflict: a change in a merge that git is
unable to automatically merge
merge conflicts
merge conflicts
merge conflicts
merge conflicts
merge conflicts
if you come across these,
please feel free to ask for
assistance!
the (updated) git flow
git checkout -b
Change branch
branch

Make changes ~ type stuff here ~

Add changes git add .

Commit changes git com m it -m m sg

Merge changes into git checkout m aster


master git m erge branch
demo
git remotes
git on the cloud
git terminology
remote: a server where you can store
your git repo
https://github.com/new
Attach your repo to GitHub:
g it rem ote ad d orig in [u rl]
git terminology
origin: the main server where you store
your git repo
View your remotes:
g it rem ote -v
git remote -v
git terminology
push: send (or, push) your git repository
to the server
Push your code:
g it p u sh orig in m aster
git remote -v
git terminology
pull: download (or, pull down) your git
repository from the server
Pull your code:
g it p u ll
git pull
bonus: GitHub
git terminology
pull request: a request to merge your
branch into master
git pull
git pull
Send a link to your new pull
request in Slack!
add contributors on GitHub
Attach your repo to GitHub:
g it rem ote ad d orig in [u rl]
demo
and thats it!
andrew on the interwebz
https://andrewjkerr.com
https://ajk.tumblr.com
@andrewuf on Twitter/Snapchat
questions?
@andrew on Slack
#git on Slack
Andrew irl