Git
-
Upload
jnewland -
Category
Technology
-
view
1.694 -
download
0
Transcript of Git
![Page 1: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/1.jpg)
![Page 2: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/2.jpg)
jnewland.com/tag/git
![Page 3: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/3.jpg)
What is Git?
• A popular distributed version control system designed to handle very large projects with speed and efficiency.
• http://git.or.cz/
![Page 4: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/4.jpg)
quick survey
• Who is not using source control?
• SVN?
• CVS? (still?)
![Page 5: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/5.jpg)
• Written by Linus Torvalds
• Written to manage the Linux Kernel
Git History
![Page 6: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/6.jpg)
Getting Git
![Page 7: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/7.jpg)
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
![Page 8: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/8.jpg)
For the weak
sudo port install git-core +svn
sudo apt-get install git-core
sudo yum install git-core
![Page 9: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/9.jpg)
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
![Page 10: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/10.jpg)
Why Git?
• Distributed, not Centralized
• Revolutionizes how you use branching
• Extremely stupidly ridiculously fast, even with large projects
• Community
![Page 11: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/11.jpg)
Centralizedvs
Distributed
![Page 12: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/12.jpg)
Centralized VCS
• Repository
• History stored in central location
• Checkout
• A ‘working tree’
![Page 13: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/13.jpg)
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.
![Page 14: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/14.jpg)
Wait, commitshappen offline?
![Page 15: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/15.jpg)
Commits happen offline!!!!!!!11!!!
![Page 16: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/16.jpg)
on the plane
![Page 17: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/17.jpg)
on the train
![Page 18: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/18.jpg)
at that crappy coffee shop with the paid WiFi
![Page 19: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/19.jpg)
at an ATLRUG meeting
![Page 20: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/20.jpg)
Branching FTW
![Page 21: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/21.jpg)
“But I don’t branch”
![Page 22: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/22.jpg)
because you don’t use Git
![Page 23: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/23.jpg)
quick survey #2
• How many of you use branching?
• Work exclusively on trunk/master?
• NEVER work on trunk/master?
![Page 24: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/24.jpg)
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
![Page 25: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/25.jpg)
Forget about ‘breaking the build’
• ‘Atomic’ commits are a thing of the past
• ‘Atomic’ merges
![Page 26: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/26.jpg)
• Prototype well-developed changes
• Commit early and often
• Review and revise before you merge
Topic Branches
![Page 27: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/27.jpg)
With Git, branches are now a part of my
everyday workflow
![Page 28: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/28.jpg)
‘Tomorrow’ branch
![Page 29: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/29.jpg)
‘Drunk’ branch
![Page 30: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/30.jpg)
Performance
![Page 31: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/31.jpg)
Offline Operations
• Performing a diff
• Viewing file history
• Committing changes
• Merging branches
• Obtaining any other revision of a file
• Switching branches
![Page 32: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/32.jpg)
Online operationsare fast too
$ time svn co http://svn.rubyonrails.org/rails/trunk/
...
real 0m29.537s
![Page 33: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/33.jpg)
Online operationsare fast too
$ time git clone --depth 1 git://github.com/josh/rails.git
...
real 0m9.088s
![Page 34: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/34.jpg)
Online operationsare fast too
$ time git clone git://github.com/josh/rails.git
...
real 0m37.512s
![Page 35: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/35.jpg)
Git for Subversion Users
![Page 36: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/36.jpg)
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
![Page 37: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/37.jpg)
Creating a Repo
$ pwd
~/src/foo
$ git init
$ git add .
$ git commit
![Page 38: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/38.jpg)
Checking out a Repo
$ git clone REPO_URL
![Page 39: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/39.jpg)
git status
• Untracked Files
• Brand new file
• Changed but not updated
• Locally changed file not in the index
• Changes to be committed
• ‘The Index’
![Page 40: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/40.jpg)
The Index
• Staging area for your next commit
• Sort of like files marked A, M, D in svn status output
![Page 41: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/41.jpg)
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.
![Page 42: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/42.jpg)
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
![Page 43: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/43.jpg)
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
![Page 44: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/44.jpg)
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
![Page 45: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/45.jpg)
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
![Page 46: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/46.jpg)
Reverting Changes
$ git checkout PATH $ svn revert PATH
![Page 47: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/47.jpg)
git revert != svn revert
# most similar to svn revert
$ git checkout .
# reverse commit <rev> and commit the result
$ git revert <rev>
![Page 48: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/48.jpg)
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
![Page 49: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/49.jpg)
More Branching# view available branches
$ git branch
* new_branch
master
# delete a branch
$ git branch -d ALREADY_MERGED_BRANCH
$ git branch -D BAD_BRANCH
![Page 50: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/50.jpg)
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
![Page 51: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/51.jpg)
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
![Page 52: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/52.jpg)
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
![Page 53: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/53.jpg)
Danger, Will Robinson
• Rebase is dangerous
• Rewrites commit history
• Don’t use on a branch you’re sharing
![Page 54: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/54.jpg)
Oh noes! Merge Conflicts!
![Page 55: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/55.jpg)
Easy Conflict Resolution
$ git merge conflict_branchAuto-merged READMECONFLICT (content): Merge conflict in READMEAutomatic merge failed; fix conflicts and then commit the result.
# fix conflict then commit
$ vim README
$ git add README
$ git commit -m “fixed merge conflict”
![Page 56: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/56.jpg)
Collaboration with GIT
![Page 57: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/57.jpg)
Hosting a Git Repo
• git-daemon
• gitosis
![Page 58: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/58.jpg)
Hosting a Git Repo
• git-daemon
• gitosis
![Page 59: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/59.jpg)
github.com
![Page 60: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/60.jpg)
Fork your friends
![Page 61: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/61.jpg)
‘MySpace for hackers’
![Page 62: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/62.jpg)
Track forks of your repository
![Page 63: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/63.jpg)
Free for public repos
![Page 65: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/65.jpg)
Common Use Cases
• Contributor
• Create Patches
• Send Patches
• Maintainer
• Review Patches
• Apply Patches
![Page 66: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/66.jpg)
Contributor
![Page 67: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/67.jpg)
Fork, then clone
• Fork repo at githubhttp://github.com/jnewland/atlrug-demo/tree/master
• Clone your copy of my repo$ git clone [email protected]/USERNAME/atlrug-demo.git
![Page 68: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/68.jpg)
Make changes
$ git checkout -b my_branch
$ echo “hello again” >> README
$ git commit -a
![Page 69: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/69.jpg)
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
![Page 70: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/70.jpg)
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
![Page 71: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/71.jpg)
Push it real good
$ git push origin master
![Page 72: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/72.jpg)
Sending Patches
• Old skool:$ git format-patch jnewland
• New hotness - ‘Pull Request’
![Page 73: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/73.jpg)
No more emailing patches
![Page 74: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/74.jpg)
No more emailing patches
![Page 75: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/75.jpg)
Maintainer
![Page 76: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/76.jpg)
Receive pull request
![Page 77: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/77.jpg)
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
![Page 78: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/78.jpg)
Merge, then push!# switch back to master
$ git checkout master
# merge
$ git merge mtodd/master
# push
$ git push
![Page 79: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/79.jpg)
SVN Integration
![Page 80: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/80.jpg)
“the best part about GIT is that no one has to know you’re using it”
![Page 81: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/81.jpg)
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
![Page 82: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/82.jpg)
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
![Page 83: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/83.jpg)
Pretty GUIs
![Page 84: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/84.jpg)
gitk
• Bundled with git
• Excellent visualization of branching history
![Page 85: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/85.jpg)
GitNub
• http://github.com/Caged/gitnub/tree/master
• RubyCocoa
![Page 86: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/86.jpg)
More Resources
• http://git.or.cz/
• http://cheat.errtheblog.com/s/git/
• http://github.com/guides
• #git and #github on irc.freenode.org
![Page 87: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/87.jpg)
Questions?Comments?
Flames?
![Page 88: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/88.jpg)
Jesse [email protected]://jnewland.com
![Page 89: Git](https://reader038.fdocuments.us/reader038/viewer/2022110307/555c2337d8b42a09438b4ab9/html5/thumbnails/89.jpg)
flickr is awesome
• http://flickr.com/photos/alper/528441936/
• http://flickr.com/photos/joan-fabregat/1947832858/
• http://flickr.com/photos/feria/2316579746/