Download - Git
![Page 1: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/1.jpg)
Git
![Page 2: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/2.jpg)
What is Git?
Distributed version control system (DVCS)
SVN = Centralized version control system
Mercurial, Bazaar are other DVCS
Initially designed and developed by Linus Torvalds to manage Linux kernel code base when BitKeeper revoked free license.
![Page 3: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/3.jpg)
SVN (Centralized VCS) overview
![Page 4: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/4.jpg)
Git (Distributed VCS) overview
![Page 5: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/5.jpg)
Git (Distributed VCS) overview (cont)
![Page 6: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/6.jpg)
Why Git?
Embraced by all major hosting sites:Github, Google Code, CodePlex, BitBucket
Used by major projectsLinux kernel, Android, ASP.NET MVC, Facebook, Eclipse, Twitter Boostrap, ...
![Page 7: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/7.jpg)
• Able to work disconnected (ex. VPN / home)o (Almost) everything is local, fasto Log is always availableo Private workspace
Able to commit whenever, create snapshots, push when ready (off VPN, done hacking)
Share when ready, ability to modify previous commits before sharing
• Local branching, easily switch gears when customer calls (isolate work units)
features, bug fixes, proof of concepts, etc
• Submodules / subtree
Why Git? - Benefits
![Page 8: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/8.jpg)
General workflow
![Page 9: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/9.jpg)
File status lifecycle
![Page 10: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/10.jpg)
Repository commits
![Page 11: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/11.jpg)
Terms
HEAD last commit of current branchHEAD^
parent of HEADmaster
default development branch (trunk)origin
default upstream repository (name of remote when git clone was used)
![Page 12: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/12.jpg)
Terms (cont.)
HEAD^ == HEAD~1 # parent of HEADHEAD^^^ == HEAD~3master^^^ == master ~3
![Page 13: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/13.jpg)
git initNew
git clone <url>Existing
run at the project's top-most directorycreates a .git directory
Initializing
![Page 14: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/14.jpg)
Review previous commitgit show --statgit show --name-status
info about last commit
git show HEADgit show HEAD^^^git show master~10git show @{yesterday}git show master@{May.16}
![Page 15: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/15.jpg)
Loggit loggit log --name-statusgit log --oneline --graph --allgit log --author="Sean Lynch"git log --grep="commit.*message.*text"git log -- some/file
limit by changes to specific file
git timeline / git lolcustom aliases
![Page 16: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/16.jpg)
Branchinggit branch <branchname>git checkout <branchname>
git checkout -b <branchname>Create new branch and switch to
git branch [-a -l -r]List branches (all, local, remote)
git merge <branchname>Merge branch into current branch (ex. master)
![Page 17: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/17.jpg)
Stashing
git stashgit stash [save message]git stash listgit status applygit stash clear
git stash branch <branchname>
![Page 18: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/18.jpg)
Making a release (tagging)
git tag -a <name>Create an annotated tag (with message)
git push --tagsPush tags to remote
git taglist all tags
![Page 19: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/19.jpg)
Remotesgit remote -vgit remote add <name> <url>git remote show <name>
git branch --set-upstream master origin/masterSet local branch to track remote branch
git svnhttp://git-scm.com/book/en/Git-and-Other-Systems-Git-and-Subversion
![Page 20: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/20.jpg)
Updating (Push/Pull)
git fetch / git mergeFetch latest changes from origin, need to use git merge to apply.
git pullPull latest changes from origin (fetch + merge)
git push [remote_name] [branch_name]
![Page 21: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/21.jpg)
Revertinggit checkout .
Revert changes to all files into working directory, overwriting any local changes. This is most similar to "svn revert"
git checkout -- <filename>Revert changes to a file in working directory
git log --diff-filter=D -- <filename>git checkout <deleting_commit>^ -- <filename>
Restore a deleted file
![Page 22: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/22.jpg)
Reverting (cont.)git reset HEAD
Unstage something
git reset HEAD^forget about a commit, load it back into the staging area
git reset --hard HEAD / git checkout -fReturn to last committed state (discard all local changes). Can not be undone (without reflog)
![Page 23: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/23.jpg)
Reverting (cont. more)git commit --amend
Change last commit (correct the previous commit, with the staged changes)
git revert HEADRevert changes (creates a new commit)
![Page 24: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/24.jpg)
Getting Started
InstallConfigurationIgnores
![Page 25: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/25.jpg)
InstallWindows
Git for Windows: http://msysgit.github.com/Git Extensions:
http://code.google.com/p/gitextensions/TortoiseGit: http://code.google.com/p/tortoisegit/
MacHomebrew: brew install git bash-completion
SourceTree: http://www.sourcetreeapp.com/GitHub for Mac: http://mac.github.com/
![Page 26: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/26.jpg)
Configurationgit config --global user.name "Sean Lynch"git config --global user.email "[email protected]"
git config --global core.autocrlf true #Windowsgit config --global core.autocrlf input #Macs
git config --global color.ui truegit config --global log.decorate true
git config --listcat ~/.gitconfig
![Page 27: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/27.jpg)
Configuration (aliases)git config --global alias.st status -sgit config --global alias.co checkoutgit config --global alias.br branchgit config --global alias.ci commit
git config --global alias.timeline=log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all
![Page 28: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/28.jpg)
Ignores
git config --global core.excludesfile~/.gitignore_global
Collection of .gitignore templates by language / framework
https://github.com/github/gitignore
![Page 29: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/29.jpg)
Review
git initgit clonegit addgit statusgit commitgit log
git branchgit checkoutgit mergegit pushgit fetchgit pull
![Page 30: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/30.jpg)
Extras - Modifying history
git commit --amendModify previous commit. Useful to update message or include missing file without creating a new commit
git rebase -iRewrite history. Squash, reorder, by dropping
![Page 31: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/31.jpg)
Extras
git submodule
git subtree
![Page 32: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/32.jpg)
Finding regressions
git bisect startgit bisect good <commit>git bisect bad <commit>git bisect visualizegit bisect reset
![Page 33: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/33.jpg)
Best practices
Don't develop off master, use develop/feature/issue/etc branches
![Page 34: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/34.jpg)
![Page 35: Git](https://reader035.vdocuments.us/reader035/viewer/2022070522/58ee7b201a28ab4d148b464d/html5/thumbnails/35.jpg)
Help / Documentation / Referencegit <command> --help
http://gitref.org/http://git-scm.com/bookhttp://help.github.com/http://www.codingdomain.com/git/tricks/http://jonas.nitro.dk/git/quick-reference.htmlhttp://gitimmersion.com/http://marklodato.github.com/visual-git-guide/