Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Git
Search
Jesse Newland
October 02, 2011
Technology
7
930
Git
Intro to Git presentation. Presented in ATLRUG in 2008.
Jesse Newland
October 02, 2011
Tweet
Share
More Decks by Jesse Newland
See All by Jesse Newland
Kubernetes at GitHub
jnewland
2
590
Migrating a monolith to Kubernetes
jnewland
6
560
Optimizing Ops for Happiness
jnewland
19
2.9k
ChatOps at GitHub
jnewland
133
39k
Puppet at GitHub / ChatOps
jnewland
68
12k
GitHub Pages on Riak and Webmachine
jnewland
56
8.5k
Web Application Monitoring with Cucumber
jnewland
6
960
Moonshine
jnewland
4
400
God
jnewland
5
470
Other Decks in Technology
See All in Technology
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
250
ハイテク休憩
sat
PRO
2
140
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
330
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.2k
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
300
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
1
110
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1k
20241220_S3 tablesの使い方を検証してみた
handy
3
320
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
440
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
210
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
Embracing the Ebb and Flow
colly
84
4.5k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Docker and Python
trallard
42
3.1k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
BBQ
matthewcrist
85
9.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Transcript
None
jnewland.com/tag/git
What is Git? • A popular distributed version control system
designed to handle very large projects with speed and efficiency. • http://git.or.cz/
quick survey • Who is not using source control? •
SVN? • CVS? (still?)
• Written by Linus Torvalds • Written to manage the
Linux Kernel Git History
Getting Git
For the brave # install gnupg, gettext $ curl -O
http://kernel.org/pub/software/scm/git/ git-1.5.4.1.tar.gz $ tar xzf git-1.5.4.1.tar.gz $ ./configure $ make $ sudo make install $ curl http://www.kernel.org/pub/software/scm/git/git- manpages-1.5.4.tar.bz2 $ sudo tar xjf git-manpages-1.5.4.tar.bz2 -C /usr/ local/share/man
For the weak sudo port install git-core +svn sudo apt-get
install git-core sudo yum install git-core
Initial Setup $ git config --global user.name='My Name' $ git
config --global
[email protected]
# optional, for pretty colors $ git config --global color.diff=auto $ git config --global color.diff.new=cyan $ git config --global color.diff.old=magenta $ git config --global color.diff.frag=yellow $ git config --global color.diff.meta=green $ git config --global color.diff.commit=normal
Why Git? • Distributed, not Centralized • Revolutionizes how you
use branching • Extremely stupidly ridiculously fast, even with large projects • Community
Centralized vs Distributed
Centralized VCS • Repository • History stored in central location
• Checkout • A ‘working tree’
Distributed VCS • Every Git working directory is a full-fledged
repository with full revision tracking capabilities, not dependent on network access or a central server. • Commits happen offline. • Commits can then be pushed and pulled between repositories with shared history.
Wait, commits happen offline?
Commits happen offline!!!!!!!11!!!
on the plane
on the train
at that crappy coffee shop with the paid WiFi
at an ATLRUG meeting
Branching FTW
“But I don’t branch”
because you don’t use Git
quick survey #2 • How many of you use branching?
• Work exclusively on trunk/master? • NEVER work on trunk/master?
Why branching with Git is awesome • Instant $ time
git checkout -b newbranch Switched to a new branch "newbranch" real 0m0.227s • Private • Merging doesn’t suck
Forget about ‘breaking the build’ • ‘Atomic’ commits are a
thing of the past • ‘Atomic’ merges
• Prototype well-developed changes • Commit early and often •
Review and revise before you merge Topic Branches
With Git, branches are now a part of my everyday
workflow
‘Tomorrow’ branch
‘Drunk’ branch
Performance
Offline Operations • Performing a diff • Viewing file history
• Committing changes • Merging branches • Obtaining any other revision of a file • Switching branches
Online operations are fast too $ time svn co http://svn.rubyonrails.org/rails/
trunk/ ... real 0m29.537s
Online operations are fast too $ time git clone --depth
1 git://github.com/josh/ rails.git ... real 0m9.088s
Online operations are fast too $ time git clone git://github.com/josh/rails.git
... real 0m37.512s
Git for Subversion Users
This looks familiar $ git status $ git log $
git blame $ git add FILE $ git rm FILE $ git mv FILE $ svn status $ svn log $ svn blame $ git add FILE $ git rm FILE $ git mv FILE
Creating a Repo $ pwd ~/src/foo $ git init $
git add . $ git commit
Checking out a Repo $ git clone REPO_URL
git status • Untracked Files • Brand new file •
Changed but not updated • Locally changed file not in the index • Changes to be committed • ‘The Index’
The Index • Staging area for your next commit •
Sort of like files marked A, M, D in svn status output
One major difference • After making any changes to the
working directory, and before running the commit command, you must use the add command to add any new or modified files to the index.
Example # create bar and to the index echo “foo”
> bar git add bar # change bar, and thus remove from the index echo “ “ >> bar # add bar to the index again git add bar
Committing • git commit • commit what’s in the index
• git commit -a • adds changed but not untracked files to the index, then commits • exactly like SVN
Diffs # diff between working tree and the index $
git diff # diff between the index and last commit $ git diff --cached # diff between working tree and last commit $ git diff HEAD
Logs # just like svn $ git log # find
a commit changed a specific string $ git log -S"def stupid_method" # log with patches for each commit $ git log -p
Reverting Changes $ git checkout PATH $ svn revert PATH
git revert != svn revert # most similar to svn
revert $ git checkout . # reverse commit <rev> and commit the result $ git revert <rev>
Branching # create a new branch $ git branch NEW_BRANCH
# switch to this branch $ git checkout NEW_BRANCH # create a new branch and check it out in one step $ git checkout -b NEW_BRANCH
More Branching # view available branches $ git branch *
new_branch master # delete a branch $ git branch -d ALREADY_MERGED_BRANCH $ git branch -D BAD_BRANCH
Diffing and Logging with Branches # log of changes to
other_branch not in master $ git log NEW_BRANCH..master # diff of those changes $ git diff NEW_BRANCH..master
Merging # get back to the master $ git checkout
master # merge in changes from your other branch $ git merge NEW_BRANCH # optionally, delete the branch $ git branch -d NEW_BRANCH
Rebasing # store local changes not in BRANCH_NAME as patches,
updates the local branch to BRANCH_NAME, then applies the patches $ git rebase BRANCH_NAME
Danger, Will Robinson • Rebase is dangerous • Rewrites commit
history • Don’t use on a branch you’re sharing
Oh noes! Merge Conflicts!
Easy Conflict Resolution $ git merge conflict_branch Auto-merged README CONFLICT
(content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. # fix conflict then commit $ vim README $ git add README $ git commit -m “fixed merge conflict”
Collaboration with GIT
Hosting a Git Repo • git-daemon • gitosis
Hosting a Git Repo • git-daemon • gitosis
github.com
Fork your friends
‘MySpace for hackers’
Track forks of your repository
Free for public repos
• Still in beta • Email me at
[email protected]
if
you’d like an invite (20 left)
Common Use Cases • Contributor • Create Patches • Send
Patches • Maintainer • Review Patches • Apply Patches
Contributor
Fork, then clone • Fork repo at github http://github.com/jnewland/atlrug-demo/tree/master •
Clone your copy of my repo $ git clone
[email protected]
/USERNAME/atlrug-demo.git
Make changes $ git checkout -b my_branch $ echo “hello
again” >> README $ git commit -a
Track the upstream # add a remote $ git remote
add jnewland git://github.com/ jnewland/atlrug-demo.git # add a branch $ git checkout -b jnewland/master # update the tracking branch $ git pull jnewland master
Merge it all together # switch back to the master
$ git checkout master # update master with your changes $ git merge my_branch # update master with upstream changes $ git merge jnewland/master
Push it real good $ git push origin master
Sending Patches • Old skool: $ git format-patch jnewland •
New hotness - ‘Pull Request’
No more emailing patches
No more emailing patches
Maintainer
Receive pull request
Grab mtodd’s changes # add a remote $ git remote
add mtodd git://github.com/mtodd/ atlrug-demo.git # add a branch $ git checkout -b mtodd/master # pull the changes $ git pull mtodd master
Merge, then push! # switch back to master $ git
checkout master # merge $ git merge mtodd/master # push $ git push
SVN Integration
“the best part about GIT is that no one has
to know you’re using it”
basic git-svn workflow $ git svn clone REPO_URL # ...
hack hack hack ... $ git commit -a # ... hack hack hack ... $ git commit -a $ git svn rebase $ git svn dcommit
better workflow $ git svn clone REPO_URL $ git checkout
-b new_branch # ... hack hack hack ... $ git commit -a $ git svn rebase $ git svn dcommit $ git checkout master $ git branch -d new_branch $ git svn rebase
Pretty GUIs
gitk • Bundled with git • Excellent visualization of branching
history
GitNub • http://github.com/Caged/ gitnub/tree/master • RubyCocoa
More Resources • http://git.or.cz/ • http://cheat.errtheblog.com/s/git/ • http://github.com/guides • #git
and #github on irc.freenode.org
Questions? Comments? Flames?
Jesse Newland
[email protected]
http://jnewland.com
flickr is awesome • http://flickr.com/photos/alper/528441936/ • http://flickr.com/photos/joan-fabregat/ 1947832858/ • http://flickr.com/photos/feria/2316579746/