W H AT I S I T ?
• Manages changes and versions of files
• Also known as:
• Source Code Management (SCM)
• Version Control System (VCS)
W H Y U S E I T ?
• Reduces risk
• Agility
• Freedom to experiment
• Collaboration
• Helps document changes
W H Y G I T ?
• Extremely fast performance
• Excellent data integrity
• Git checksums everything (SHA-1)
• Easy to learn and to start small
G I T O V E R V I E W
• Distributed
• All clients have the full repo
• Backups are everywhere
• Local repo updated before remotes
• When available, push updates to remote
G I T V E R S U S S U B V E R S I O N
• Much faster checkouts
• Clients have full project
• Distributed versus centralized
• Network access optional*
• Much simpler ignores
• Seamless renames and moves
• Easier branching and merging
H O W T O I N S TA L L G I T
• Embedded with many Git GUI Apps
• Download from http://git-scm.com
• OS X: Terminal.app
• Windows: Git Bash
• Linux: Terminal
• OS X: MacPorts and HomeBrew
C O N F I G U R I N G G I T
• Git GUI clients handle it for you, or …
• $ git config
• Contains items such as name, email, editor, diff tool
A D D F I L E S T O T H E R E P O
Working Directory
Staging AreaAdd
• Add (stage) files for the next commit
C O M M I T F I L E S T O R E P O
Working Directory
Staging AreaAdd
RepositoryCommit
• Save staged files to the project repository
C O M M I T M E S S A G E S
• Commit often - You will thank yourself later!
• Or else … Larger changes are much harder to pick apart and revert back to!
• Each commit should encapsulate a single fix*
R E V I E W I N G D I F F S
• Very easy to view with GitHub client and web
• External diff apps
• FileMerge
• Kaleidoscope
H I S T O R Y L O G S
• Review history of commits to repo
• Extremely helpful for your future self and others
G I T C L I E N T A P P S
• http://git-scm.com/downloads/guis
• GitHub
• https://mac.github.com
• https://windows.github.com
• SourceTree
• https://www.sourcetreeapp.com
G I T H U B
• Simplifies the complex Git tasks
• Integrates well with GitHub remote web service
• Easy to start with
• Limited feature set (by design)
G I T H U B A N D S TA G I N G F I L E S
• Be aware …
• The GitHub app does not show staged items.
• So, why doesn’t it?
• And why are you tell us this, Justin?!
B R I N G I T A L L T O G E T H E R
• Create repo
• Commit file
• Modify the file
• View file diff, commit
• Ignore files, commit
• Review history logs
R E M O T E R E P O S
• Local repo on your client only
• Remote is a Git host to push to
• You clone from remotes
• First remote is called “origin”
S E L F - H O S T E D R E P O S
• SSH
• Enable SSH, create “bare” repository on server
• Atlassian Stash
• Enterprise GitHub
• GitLab
R E M O T E R E P O H O S T S E R V I C E S
• 3rd Party
• GitHub, BitBucket
• CodeSpaces, SourceRepo
• Assembla, Gitorious
• git.psu.edu (For Penn Staters)
• And possibly more, I’m sure…
F E T C H I N G
• Updates repo status of remote
• Local repo files not changed
• Tip: Fetch before pushing to remotes
R E M O T E S D E M O
• Create repo on GitHub (the remote)
• Adds remote ref to local repo settings
• Local branches track remote branches
• Push full local repo to remote
• Commit locally, push to origin remote
• Create README.md file on GitHub, Pull
B R A N C H E S
• When to use them?
• “master” is the default branch
• Merging of branches is where Git really excels
B R A N C H E S
• Help to separate lines of development
• “Git Flow” is a popular branching model
• Ex: Master, Hotfix, Development, Feature, Release
B R A N C H W A L K T H R O U G H
M 1
Merge Branch To Master
B 1 B 2 B 3 B 4
M 2
(Branch Deleted
After Merge)
H E A D R E F E R E N C E
• Checking out commit older than latest on branch
• No code changes! Or …
• Create a new branch FIRST
C O N F I G U R E L I N E E N D I N G S
• End of line characters differ based on client OS
• OS X and Linux use one invisible character
• LF (Line Feed)
• Windows uses two invisible characters
• CR (Carriage Return) + LF (Line Feed)
• Embrace the native line endings for each OS
L I N E E N D I N G M O D E S
• core.autocrlf true
• Use for cross platform projects on Windows clients
• core.autocrlf input
• Use for cross platform projects on OS X clients
• core.autocrlf false
• Use only on single platform projects
L I N E E N D I N G S O N W I N D O W S
Enable auto convert to LF on Windows by using git config to set core.autocrlf to true:
L E S S O N S L E A R N E D
• Start small
• Pick just one project to manage with Git
• Use remotes when ready
• GitHub, BitBucket
• Your own SSH host
L E S S O N S L E A R N E D
• Write good commit messages
• There will be a time when you need to search your commit messages and it will really help you out!
• Be nice to your future self.
• “Where / when / how did I fix that issue?”
• What’s for the release notes?
R E S O U R C E S A N D T R A I N I N G
• Official Git Site
• http://git-scm.com
• Git Cheat Sheets
• Git Pro Book
R E S O U R C E S A N D T R A I N I N G
• http://try.github.com
• http://atlassian.com/git
• O’Reilly
• “McCullough and Berglund on Mastering Git”