Professional Documents
Culture Documents
ihower@gmail.com
2011/3
CC BY-NC-SA 3.0
Pro Git
a.k.a. ihower
http://ihower.tw
http://twitter.com/ihower
Ruby on Rails Developer since 2006
The organizer of Ruby Taiwan Community
http://ruby.tw
2
Agenda
1. DVCS
2. Git
3. Git
4. Github
5. Git
2002 ( copy )
2005 SubVersion
2007 SVK
2008 Git ( SVN push/pull)
2009 Git ( master feature branches)
2011 Git ( git flow topic branch rebase)
1. DVCS ?
Branch()
Tag()
Local VCS
Local VCS
Centralized VCS
CVS, Subversion, Perforce
Centralized VCS
CVS, Subversion, Perforce
1.
Distributed VCS
Git, Mercurial(Hg), Bazaar
Distributed VCS
Git, Mercurial(Hg), Bazaar
workflows
!
Local development
CSV
commit history log
CSV
commit history log
10
2. Git ?
11
Git
Linux Torvalds (Linux creator)
Linux Kernel
2005/4 2005/6 Linix
Kernel2005/12 1.0
12
Git?
Git
Linux Kernel
Perl
Eclipse
Gnome
KDE
Qt
Ruby on Rails
Android
PostgreSQL
Debian
X.org
13
14
Git Way
metadata snapshots
15
Git Way
metadata snapshots
Im a mini filesystem!
Not just VCS.
15
Git Way
metadata snapshots
Im a mini filesystem!
Not just VCS.
Apple Time
Machine !
15
16
Git
Git
Staging
GitHub!
Git
SVN
svn merge
branch branch
svn log
svn commit checkout
commit
18
3-1. Git
19
Install
Git
http://help.github.com/set-up-git-redirect
Git GUI(optional)
GitX (Mac)
TortoiseGit/Git Extensions (Windows)
qgit (Linux)
SSH Key
ssh-keygen -t rsa -C "your_email@youremail.com"
20
Setup
~/.gitconfig
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global color.ui true
git config --global core.editor "mate -w" (Textmate)
21
22
Repository
mkdir sandbox
cd sandbox
git init
23
Repository
SSH
git clone git@github.com:ihower/sandbox.git
HTTP/HTTPS
git clone https://ihower@github.com/ihower/sandbox.git
Git protocol ()
git clone git://github.com/ihower/sandbox.git
commit
touch README
git add README
git status
git commit -m First Commit
25
README
git status
git diff
git add .
(!)
git status
git diff --cached
git commit -m Update README
26
Staging commit
touch a.rb
touch b.rb
git add a.rb
git commit Update a
git add b.rb
git commit Update b
27
git rm a.rb
git mv b.rb c.rb
git add .
git commit Remove a, Rename b to c
copy ? Git
cp
28
commit
Untracked files
Changes not
staged for commit
Changes to be
committed
29
git log
git log --oneline
git log --oneline --decorate --graph
GUI
30
.gitignore ( commit )
~/.gitignore ( Global )
commit
.gitkeep
.gitignore
https://github.com/github/gitignore
31
commit ?
tmp/*
log/*
()
build/* compile
.DS_Store
Thumbs.rb
32
Commit
//
bug fixed
unit test commit
commit
commit
33
3-2. Git
34
Branch ?
topic feature
Bug fixes
(refactor)
35
branch
git branch new_feature
git branch
git checkout new_feature
touch new_feature.rb
git add new_feature.rb
git commit -m New feature
36
branch
git branch new_feature
git branch
git checkout new_feature
touch new_feature.rb
git add new_feature.rb
git commit -m New feature
checkout
working tree
36
branch
git checkout master
git merge new_feature
37
38
39
40
41
42
fast-forward
42
43
44
C6 merge
commit
44
Straight merge
branch commits
merge commit
Parents
fast-forward merge
commit --no-ff
45
(cont.)
Squashed commit
git merge new_feature --squash
merge-commit
logSVN merge
cherry-pick
git cherry-pick 714cba
commit
46
branch
working tree branch
staging area modified
commit push
reset
stash
git stash
git stash apply
git stash clear
47
48
push branch
...
SVNGit Commit
commit logs!!
commits
commit
commit commits
commits
49
reset ( commit )
git reset e37c75787
git reset HEAD^ ( working tree)
git reset HEAD^ --soft ( staging area)
git reset HEAD^ --hard ()
50
revert ( commit )
reset revert commit
51
rebase ( commit )
git rebase -i e37c7578
pick 048b59e first commit
pick 995dbb3 change something
pick aa3e16e changed
#
#
#
#
#
#
#
#
#
#
#
#
: rebase
rebase ( local branch)
1. branch
2. branch commits
apply/patch
commit log
local branch
53
: new_feature
master
D---E new_feature
/
A---B---C---F master
54
merge
(new_feature) git merge master
D--------E
/
\
A---B---C---F----G new_feature
master
55
rebase G !
(new_feature) git rebase master
A---B---C---F---D'---E' new_feature
master
56
rebase G !
(new_feature) git rebase master
A---B---C---F---D'---E' new_feature
master
merge commit
56
push commits
push !!
57
rebase + merge
( feature branch develop)
merge
commit
59
(1)
--no-ff merge commit
fast-forward
rebase feature branch push
feature branch
60
(2)
rebase conflict
rebase
branch rebase
61
4. Github ?
62
GitHub?
twitter
facebook
rackspace
digg
Yahoo!
shopify
EMI
six apart
jQuery
YUI 3
mootools
Ruby on Rails
node.js
symfony
mongodb
Erlang
65
Watch!
Fork
67
Fork network
68
Patch ?
Fork Repository
Clone
Fix bugs Enhance features
Push
Pull request
69
70
Follow!
Wiki
72
Code Review
Diff
Download Source
or Package
74
Github pages
http://pages.github.com/
your.github.com repositoryGithub
http://your.github.com
gh-pages your_projectGithub
http://your.github.com/your_project
75
Github pages
http://pages.github.com/
your.github.com repositoryGithub
http://your.github.com
gh-pages your_projectGithub
http://your.github.com/your_project
Git
( Branch merge)
75
3-4. Git
76
77
Pull
git pull origin master git pull
git fetch branch
branch merge
78
79
branch
master
!
79
conflict
--rebase
80
conflict
--rebase
git flow
branches
merge !
80
Git Submodule
Git SVN
? SVN Externals?
http://josephjiang.com/entry.php?id=342
? http://josephjiang.com/entry.php?id=357
Ruby/Rails Develops XD
Bundler dependencies
81
git tag
git archive
git bisect
git blame
git grep
git show
git reflog ( commits 90)
git gc
82
5. Git
83
1.
Repositories ?
84
Centralized Workflow
Push Repository
Branches ()
85
Integration-Manager Workflow
86
87
2. Repository
Branches ?
88
http://nvie.com/posts/a-successful-git-branching-model/
http://ihower.tw/blog/archives/5140
89
master: production-ready
develop:
90
(1)
Feature branches
bugs
develop
merge develop
develop
( merge rebase)
91
(1)
Feature branches
bugs
develop
merge develop
develop
( merge rebase)
branch!!
91
(2)
Release branches
release bugs
develop
merge master develop
92
(3)
Hotfix branches
release master
master
merge master develop
93
: Feature branches
: develop
release branches
: hotfix branches
: master
94
git-flow
git flow init
git flow feature finish feature_name
git flow feature publish feature_name
git flow feature track feature_name
git flow feature finish feature_name
95
Branch-Owner Policy
project leaders commit/merge
develop branch
release team master branch
topic branches pull
request code review
merge develop
GitHub pull request
96
Code Review
97
Branch Diff
98
http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html
100
101
git-svn
SubVersion
Git Git !
git svn clone http://url/svn/trunk/ project_name
(normal git operations)
git svn dcommit
102
http://progit.org/book/
http://git-scm.com
http://help.github.com/
http://gitimmersion.com
http://www.gitready.com/
http://gitref.org
http://ihower.tw/blog/category/git
Pragmatic Version Control Using Git, Pragmatic
103
Thank you.
google ihower
104