Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Git and Github
May 08, 2013
Git and Github
May 08, 2013
More Decks by 高見龍
See All by 高見龍
Other Decks in Technology
See All in Technology
See All Featured
Git and Github eddiekao@NCKU
Current Status 80% iOS app, 20% Ruby/Rails
Before we start..
You may create lots of ﬁles day by day..
edit them, save, edit them, and save.. x N
Ctrl-C + Ctrl-V
"ProjectA" -> "ProjectA20130506" -> "ProjectA20130508-1" -> "ProjectA20130508-2" -> "ProjectA-bak" ->
backup and sync on LAN
but the problem is..
when network or svn server is down..
Is there any better way..?
Version Control System (VCS)
created by Linus Torvalds for managing Linux kernel source code
remote, and also local
Git != Github
Why version control?
backup just like you can load saving data while playing
history and evidence you know whom to blame when something
is going wrong :)
fast & smaller footprint
http://git-scm.com/book/en/Getting-Started-Git-Basics some other version control system..
just snapshots, not differences
local commit and remote push
most of the operations are local
easy to co-work with others
git is easy to use, but hard to master
on Mac: > brew install git on Ubuntu or some
linux OS: > sudo apt-get install git-core or > sudo apt-get install git
Exercise: please install git in your machine.
How to Git
.gitconﬁg it should locate in your home directory
set your username and email > git conﬁg --global user.name
"eddie" > git conﬁg --global user.email "firstname.lastname@example.org" list all settings > git conﬁg --list
make some useful aliases
[alias] co = checkout br = branch aa = add
--all l = "!source ~/.dotﬁles/.githelper && pretty_git_log" https://github.com/kaochenlong/eddie-dotﬁles
Exercise: 1. set your username and email for git. 2.
edit the ".gitconﬁg" and add some aliases.
don't be afraid of command line tools
Exercise: please create a new directory and initialize for git
git clone git://github.com/kaochenlong/eddie-vim.git
Exercise: please try to copy a project from Github or
somewhere to your local machine.
working, staging, and repository
git add can add a single ﬁle or all modiﬁed
ﬁles, even a single line.
Exercise: add a new ﬁle named "hello.rb" and add to
Exercise: after adding "hello.rb" to staging area, then try to
modify it and see what happen?
Exercise: try to check if "hello.rb" is in staging area,
and then remove it from staging area.
Exercise: add "hello.rb" to staging area, and then rename it
Exercise: just commit it :)
When to make a Commit?!
commit message matters!
amend committed message
git commit --amend
Exercise: you just committed with a rubbish message, pleases amend
it to make sense for your project.
Exercise: in last commit, you forgot to add another ﬁle,
but you don't want to commit again just for this single ﬁle, please try to commit it with -- amend.
Notice: empty folder won't be committed!
if you still want to commit an empty folder, you
can put an empty “.gitkeep” ﬁle in it by convention.
git log --pretty=oneline
git log --pretty=format:"%h %s"
git help log
Exercise: check your commit log
Exercise: read the help manual of “git log”, and make
your prefer log format.
Exercise: modify something in the "world.rb" then commit again.
Exercise: remove a ﬁle and then checkout it back.
tag is a milestone
Exercise: create a tag for your project
branching is very cheap
When to make a Branch?!
Exercise: 1. create a new branch name "fruit" 2. checkout
to "fruit" branch 3. add a "banana.rb" and commit it
Exercise: please try to list all branches, including local and
Exercise: you accidentally delete the "world.rb" ﬁle, please try to
recover it with git commands.
Exercise: you just create a tag name “ncku”, try to
checkout to this tag after several commits.
Exercise: 1. checkout back to "master" branch 2. merge "fruit"
to "master" 3. remove "fruit" branch if you like
git reset soft v.s. hard
Exercise: reset a ﬁle to untracked status which you just
added to staging.
Exercise: you just merged a branch, please try reset it
to back to un-merged branch.
git pull = git fetch + git merge
git push origin ncku-branch
git clean remove untracked ﬁles
git stash apply, pop, list, clear
1. Pro Git 2. ihower's blog http://ihower.tw/git/
on Mac: > brew install git-ﬂow on Ubuntu or some
linux OS: > sudo apt-get install git-ﬂow https://github.com/nvie/gitﬂow/wiki/Installation
Exercise: please install git ﬂow in your machine, and initialize
a git ﬂow project.
init a project with git ﬂow > git ﬂow init
Branches Master, Develop, Feature, Release, Hotﬁx
add a new feature: > git ﬂow feature start my_new_feature
when done with the new feature: > git ﬂow feature ﬁnish my_new_feature
Exercise: your boss ask you to add a new feature
which can let user upload their photos, please try to ﬁnish this assignment in git ﬂow.
Exercise: your boss ﬁnd a bug and ask you to
ﬁx it ASAP, please try to do this assignment in git ﬂow.
a git repository server
coders' facebook :)
make friends with other awesome coders :)
resume for coders!
How to Github?
Exercise: register a new account on Github
Exercise: generate a SSH key pair in your local machine
and add the public key to Github
Exercise: create a new repository on Github
Exercise: upload your project to Github
Exercise: 1. clone a project from Github 2. do some
changes 3. commit and push back to Github
Exercise: 1. create a new local branch 2. add some
change and then push this branch to Github
tag won't be pushed to repo by default
push a tag: > git push origin v2.0 push several
tags: > git push origin --tags
Exercise: create some tags for your project and upload them
Exercise: 1. fork a project from your classmate who is
sitting just next to you. 2. add some change and commit. 3. ﬁre a pull request.
host static ﬁles for FREE
upload ﬁles via git commands
User pages kaochenlong.github.io
Project Pages gh-pages branch
custom domain name
Exercise: 1. create a github page for your account. 2.
set your domain name in CNAME if you have one.
bitbucket free private repo
git + dropbox
What's inside the .git folder?