Git Workshop
Agenda:
• git highlights
• basic workflow description
• hands on : workshop
• pull requests (code reviews)
• merge conflicts
• undoing things
Please ask questions
different session - advanced stuff, rebase, hooks, git internals, releng policies.
Git Highlights
• git is distributed version control (not centralized)
• a simple command-line utility
• manipulate locally, then synchronize
• .git/ dir is 'the database'
• a few commands get you there
• all you really need is 5 or 6 commands
• branching happens a lot, because it's fast and easy
Terms and Concepts
The three states of things: committed, modified, staged
committed - safely stored in your local .git dir

modified - differs from what is in .git dir
staged - marked to go into the next commit (least important)
Terms and Concepts
Three sections of a git project:
1 .git directory
2 working area - files you manipulate on your file system


Terms and Concepts
3 staging area - list of what goes in the next commit

not always used... more later
Terms and Concepts

SHA-1 Checksums
whats with all the - 844f3cb539bc493df91f6520ed6a5eff12290ba0
Everything in git is check-summed (using SHA-1) before it's stored then referred to by that checksum. This means it's impossible to change the contents of any file or directory without git knowing about it.
Pull Request Workflow
git clone - copy repository to our local machine
git branch my-grand-plan - create a feature branch
git checkout my-grand-plan - switch to your branch
do something useful - add files, edit files, rename, delete, ...
git add - stage file(s) for commit (some or all)
git status - used throughout
...
Pull Request Workflow (cont)
git commit - save files to your local .git/
git checkout master - switch back to the master branch
git pull - pull down other people's work
git checkout my-grand-plan - back to your branch
git merge - need to merge your work with theirs
git push - push our feature branch up to bitbucket
create the pull request in Bitbucket
Basic Exercise
History and Diffs
git log - show list of commits
git blame - who changed wh
git diff - show me what i've modified
git diff --staged - show diff between staging area and working files
Undoing Things
"I've edited a file, but I want to go back to the way it was before I started"
git checkout file - caution, no undo
"I started editing in the master branch instead of creating a feature branch"
git checkout -b my-feature-branch
"I committed a change, but I made a mistake"
just make another commit
Merge Conflicts

Uh oh...
git status - show you what happened
fix the >>>>> <<<<
git add file - to tell git you've fixed the conflict
git commit - to commit your fixes
other git tools
- IDEs (IntelliJ, Eclipse, webstorm, ...) integrate
- github desktop: desktop.github.com

- available for windows/mac
- useful to view commit history and ease of use if not familar with command line
- don't need a github account, skip setup and use the command line to clone repos you're wanting to work in
- then 'add repository and browse to local path'
Git Resources
UI code -> gitdpsg update
releng team finishing up prep tasks - date TBD should be communicated soon.
login to gitdpsg with your AD creds, upload your ssh keys - new repo will be locked down and not have public http:// accessible repos
while logged in: View Profile/Notification Settings -> PR Immediately or batched
Scenarios
"I want to see what changes will be applied before I do a pull"
git fetch origin
git log -p HEAD..origin (separate commits)
git diff HEAD...origin (single diff)
Scenarios
"If I forget to create a feature branch, and instead commit my change to master, how do I pull my work into a feature branch"
on the master branch
git reset HEAD^ - undo the last commit
git checkout -b feature-branch
git-training
By Christian Parker
git-training
- 1,498