Git Magic: Versioning Files like a Boss
Upcoming SlideShare
Loading in...5
×
 

Git Magic: Versioning Files like a Boss

on

  • 1,858 views

Video available at: http://cs50.tv/2011/fall/seminars/Git_magic/Git_magic.mp4

Video available at: http://cs50.tv/2011/fall/seminars/Git_magic/Git_magic.mp4

Statistics

Views

Total Views
1,858
Views on SlideShare
1,857
Embed Views
1

Actions

Likes
3
Downloads
25
Comments
0

1 Embed 1

http://www.docshut.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • mkdir repo\nvim index.php: \nvim page.php: \ngit init\n
  • \n
  • git status\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git add --all\ngit commit\n
  • \n
  • \n
  • vim page2.php: \nvim index.php: \ngit add --all\ngit commit -m “another commit”\ngit log\n
  • \n
  • git show\ngit show PREVIOUS COMMIT\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git branch test\ngit branch\ngit checkout test\ngit branch\nvim crazy.php: \ngit add --all\ngit commit -m “so crazy up in here”\nls\ngit log\ngit checkout master\nls\ngit log\n
  • \n
  • \n
  • git branch\ngit checkout master\nvim index.php: \ngit add --all\ngit commit -m “third commit on master”\ngit merge test\ngit log\n
  • git branch -D test\ngit branch\n
  • \n
  • \n
  • git log --graph\ncd ../rebased\ngit checkout master\ngit rebase test\ngit log --graph\ncd ../repo\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ls\ngit log\nvim index.php: \ngit commit -a -m “sweet”\nvim index.php: \ngit commit -a -m “oops”\ngit revert to commit “sweet”\nCONFLICT!\ngit status\nvim index.php\ngit commit -a -m “revert”\ngit log\n
  • vim index.php: \ngit add --all\ngit checkout -- index.php\nvim index.php\ngit checkout index.php\nvim index.php\n
  • git reset --hard HEAD\n
  • git checkout \ngit log\ngit reflog\ngit checkout master\n
  • git bisect good \ngit bisect bad HEAD\ngit bisect bad\ngit checkout master\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • git remote add origin git@github.com:tmac721/seminar.git\ngit remote\ngit remote show origin\ngit push origin master\n
  • cd ../\ngit clone git@github.com:tmac721/seminar.git\ncd test\nls\ngit log\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ssh cloud\nmkdir repo\ncd repo\ngit init --bare\ncd hooks\nvim post-receive: copy this\nchmod a+x post-receive\ngit remote add origin ssh://tmacwill@cloud.cs50.net/home/tmacwill/repo\ngit push origin master\n\n
  • \n
  • \n
  • \n
  • \n

Git Magic: Versioning Files like a Boss Git Magic: Versioning Files like a Boss Presentation Transcript

  • Git Magic:Versioning Files Like a Boss Tommy MacWilliam tmacwilliam@cs50.net
  • Today• setting up like a boss• basic git like a boss• using branches like a boss• reverting changes like a boss• collaborating like a boss
  • Git is...• “Git is distributed version control system focused on speed, effectivity and real-world usability on large projects” • “distributed development” • “non-linear development” • “efficient handling of large projects” • “cryptographic authentication of history”
  • Git is...
  • Git is...Awesome.
  • Installing Git• Windows: http://code.google.com/p/ msysgit/• OS X: http://code.google.com/p/git-osx- installer/• Appliance: already installed!
  • Installing Gitroot@appliance(~): gitusage: git [--version] [--exec-path[=<path>]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [-c name=value] [--help] <command> [<args>]
  • git config --globaluser.name“Tommy MacWilliam”
  • git config --globaluser.emailtmacwilliam@cs50.net
  • git init
  • Commits• snapshots of your project• what your files look like at a given point• single event in project history
  • git status
  • git add index.php
  • git add --all
  • git add --all
  • git add --allgit commit
  • Commit Messages• short message describing what’s different in this commit• add any new features?• fix some bugs?• break anything?
  • Commit Messages
  • Commit Messages• http://www.commitlogsfromlastnight.com/
  • git commit -a -m “oh hi, mark!”
  • git log
  • 5aeebab117b892fa42002146e4c62be676bc4621b43b0ad1e8108e7ab870d7a54feac93ae8b8600e461476587780aa9fa5611ea6dc3912c146a91760
  • Commit 5aeebab117b892fa42002146e4c62be676bc4621 ID b43b0ad1e8108e7ab870d7a54feac93ae8b8600e 461476587780aa9fa5611ea6dc3912c146a91760HEAD
  • git show
  • git show b43b0
  • git initgit status git addgit commit git log git show
  • git initgit status git addgit commit git log git show
  • Branches• non-linear development process • changes on one branch do not affect other branches• crazy idea? make a branch• didn’t work? delete the branch• all done? merge the branch
  • git branch test
  • git branch test
  • git branch testgit checkout test
  • 5aeeb b43b0 46147master
  • 5aeeb git branch test b43b0 f862f 46147 36223master test
  • git merge
  • 5aeeb b43b0 f862f 46147 36223 git merge 87aedmaster test
  • Like a boss.
  • git branch -D test
  • Merge vs. Rebase• git merge: new commit, non-linear history• git rebase: no new commit, linear history
  • 5aeeb git branch test b43b0 f862f 46147 36223master test
  • 5aeeb b43b0 git rebase 46147 f862f 36223master
  • Conflicts• change in one branch can be incompatible with another• git tries to resolve, but sometimes cannot
  • Conflict Resolutionint main(int argc, char** argv) { printf(“you invited all my friends”);}int main(int argc, char** argv) { printf(“good thinking!”);}
  • Conflict Resolutionint main(int argc, char** argv) { <<<<<<< HEAD:file.c printf(“you invited all my friends”); ======= printf(“good thinking!”); >>>>>>> f862f:file.c}
  • git checkout git branch git merge git rebase
  • git checkout git branch git merge git rebase
  • git commit -m “oops.”
  • git revert b43b0
  • 5aeebb43b046147
  • 5aeebb43b046147 git revert b43b0 42bb4(b43b0)
  • File-Specific Reverts• git checkout -- index.php • replace with version in index• git checkout b43b0 index.php • replace with version in commit b43b0
  • git reset --hard b43b0
  • git reflog
  • git bisect
  • Like a boss.
  • git revert git resetgit checkout git bisect
  • git revert git resetgit checkout git bisect
  • “distributed development”
  • ssh-keygen
  • git pushgit@github.com:cs50/project master
  • git remote add origingit@github.com:cs50/project
  • git remote add origingit@github.com:cs50/projectgit push origin master
  • git clonegit@github.com:cs50/project
  • git pull origin master
  • git pull --rebase
  • git initgit add --allgit commit Alice Bob
  • git remote add origin urlgit push origin master Alice Bob
  • git remote add origin urlgit push origin master Alice Bob
  • git clone urlAlice Bob
  • git clone urlAlice Bob
  • git add --all git commitAlice Bob
  • git push origin masterAlice Bob
  • git push origin masterAlice Bob
  • git pull origin masterAlice Bob
  • git pull origin masterAlice Bob
  • git branch -a
  • git checkout -b origin/test
  • scp ~/.ssh/id_rsa.pubhost:~/.ssh/authorized_keys
  • git init --bare
  • git remote add liveuser@cloud.cs50.net:~/project
  • git remote add liveuser@cloud.cs50.net:~/project git push live master
  • Hooks• applypatch-msg • post-applypatch• commit-msg • pre-commit• post-commit • pre-commit-msg• post-receive • pre-rebase• post-update • update
  • post-receive#!/bin/shGIT_WORK_TREE=/home/tmacwill/public_html git checkout -fchmod -R 644 /home/tmacwill/public_html/*.htmlchmod -R 600 /home/tmacwill/public_html/*.php
  • Like a boss.
  • git clonegit pushgit remote git pull
  • git clonegit pushgit remote git pull
  • More Resources• http://progit.org/book/• http://book.git-scm.com/• http://gitref.org/• http://git-scm.com/documentation
  • git commit -a -m “thanks!”