Upload
glenasmith
View
1.911
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Download the powerpoint and checkout the speaker notes for some ideas around exercises.
Citation preview
Git Quickstart
Revision Control for Rock Stars
Introductions
How would you know this course was valuable a week from now?
Course Outline
• Getting Setup• Git: The Big Picture• Everyday Git• Branching• Merging & Rebasing• Other Random Gitness• Putting It All Together• Where to from here?
Outcomes & Compentencies
• Install and Configure Git for Windows• Create local and shared Git repos• Add, Remove & Commit Files to repos• View History of Files / Work with Diffs & Blames• Branch, Tag and Merge & Rebase Branches
(with Conflicts)• Back out of trouble & drama• Be able to Push, Pull, Fetch, Clone, Diff &
Branch Remote Repos• Formulating Team Workflows with Git
Philosophy
• “One must learn by doing the thing; for though you think you know it, you have no certainty, until you try.” Sophocles
• “Where there are no oxen, the manger is clean, but abundant crops come by the strength of an ox.” Jewish Proverb.
• Experiment. Go Crazy. Type like a madman.
MODULE 0: GIT - THE BIG PICTURE
What? When? Why?
Git: The Big Picture
Use Cases
• Individual Developer• Local Workgroup• Distributed Workgroup• Offline Usages
Git vs Svn vs CVS vs ?
• Snapshots, not diffs• Blobs• Everything is local• Everything is fast
What’s This “Commit” Thing?
7ef7ab ef3ad2 22e4ff
File1.txtFile2.txt
File3.txtFile1.txt
File4.txt
Git WorkflowWorkin
g Directo
ryStaging
Area (Index)
Repository
Add
Commit
Checkout
1. GETTING SETUPGetting things installed…
GUIs or Commandline or IDE?
• Git Bash• Posh Git (Powershell)• GitHub for Windows• Tortoise Git• Eclipse Git / IntelliJ Git / Visual Studio
Git Plugin / etc
Download Git for Windows
Installation Options
The Magic Path Dialog
Checkout Conventions
Commandline Once-off Magic
• git config --global user.name “Glen Smith”
• git config --global user.email “[email protected]”
• git config -l [--global]• git help config
MODULE 2: EVERYDAY GITThings you’ll use every single day…
Everyday Git: Getting Committed
• git init .• git init myproject
• git status
• echo This is a sample file > sample.txt
Adding and Committing
• git add .• git add myfile.txt myotherfile.txt• git add “**.txt”• git status• git commit -m “My first commit!”• git commit• git commit -am “Add all files and
commit. I live on the edge”
Formatting Commits
• set GIT_EDITOR=notepad• git config --global core.editor
“notepad“
• First line for short form.• Second line blank.• Third line for a long description of the
commit
Diff & Blame
• git diff• git blame /path/to/my/file.txt• git gui blame /path/to/my/file.txt• git whatchanged /path/to/my/file.txt • gitk /path/to/my/file.txt
Viewing History
• git log • git log --oneline• git log --oneline -3• git log -p• git log --since “last week” --until “2
days ago”• gitk
What’s with the SHA1?
Deleting and Renaming Files
• git rm badfile.txt
• git mv oldname.txt newname.txt
• git clean -n (dry run)• git clean -f (force)
Ignoring Files
• .gitignore• Ignore file(s), directories, patterns
(one per line)• Great for ignoring files and
directories in your project• Specially good for build artefacts and
generated binaries
Unstaging a File
• git reset HEAD myfile.txt• git checkout myfile.txt• git rm –cached myfile (only pre first
commit)
Amending A Commit
• (stage the files you want)• git commit --amend
The Reflog
• git reflog• git checkout <your-commit-sha1>• git checkout master
MODULE 3: BRANCHING & TAGGING
Working with Lines of Development
Our Story So Far…
7ef7ab ef3ad2 22e4ff
What could you use branches for?
• Bug fixes• Experimental features• Release branches• Integration Branches (CI)
In Reality…
7ef7ab ef3ad2 22e4ff
ab4efa 6e3fd1
ee7ee7
Developer Branches for
an experimental
feature..
Merges his Changes back to the master
Branching
• git branch• git branch mynewbranch• git checkout mynewbranch• git checkout -b
mynewcheckedoutbranch• git branch -d deletethatbranch
Stashing
• git stash• git stash list• git stash apply• git stash pop• git stash clear
Merging
• git merge branchname• git log master..dev
22e4ff
6e3fd1
ee7ee7
Merge creates a new commit with two parents
Handling Conflicts
• git status• git checkout --ours myfile.txt• git checkout --theirs theirfile.txt
Helpful Branch Tools
• gitk• git log --graph --oneline
Tagging
• git tag 1.0• git tag -f 1.0• git tag -a 1.0• git tag
Working with Remotes
• mkdir ourrepo.git• cd ourrepo.git• git init --bare• git clone file://c:/data/shared/ourrepo.git (or)• git remote add origin file://
c:/data/shared/ourrepo.git• git push origin master• git remote -v
Pushing, Fetching, Pulling
• git pull• git fetch• git push• git push --tags• git log master..origin/master
Remote Branches
• git push origin mybranch• git push origin• git branch -r• git checkout -b mybranch
origin/mybranch
• git config --global push.default matching
• git config --global push.default simple
Deleting Remotes
• git branch -r • git push origin :mybranch• git push origin --delete mybranch• git remote prune
MODULE 4: MERGING AND REBASING
Back in the Day..
7ef7ab ef3ad2 22e4ff
ab4efa 6e3fd1
ee7ee7
Developer Branches for
an experimental
feature..
Merges his Changes back to the master
Enter The Rebase…
7ef7ab ef3ad2 22e4ff
fad3e1ab23d
6
ee7ee7
Warning!
• ONLY rebase on a local repo, never rewrite shared history
• If you’ve pushed your changes, live with it
• You can use git revert to develop compensating commits
Rebase Essentials
• git checkout mybranch• git rebase master• git checkout master• git merge mybranch
And when there are conflicts?
• git rebase --abort• git rebase --skip• git rebase --continue
Rewrite History with Rebase
• git rebase -i <parent-of-the-commit-to-start-from>
• (entries will appear from oldest to newest)
MODULE 5: OTHER RANDOM GITNESS
Stuff that doesn’t fit elsewhere…
Git Aliases
• git config --global alias.co checkout• git config --global alias.ll “log --
oneline –graph” • git config -l• git config --unset alias.ll
Soft and Hard Resets
• Provide a way of moving HEAD in your current branch
• Hard resets throw away working tree• Soft resets preserve working
7ef7ab ef3ad2 22e4ff ee7ee7
Normally HEAD would point to here
Deployment Options
• Create a bare repo on the shared drive and use file: protocol
• Host it on a shared Unix host and use the ssh: protocol
• Run a local git daemon!
Submodules
• git submodule add <your-git-submodule-repo>
• git submodule init• git submodule update
Git Revert
Git Bundle
MODULE 6: PUTTING IT ALL TOGETHER
Choosing a Team Workflow
1. Master is always golden (merge from CI/Dev branch)
2. Branch off master approaching release
3. Release Branch Centric4. <Your Strategy Here>
Git(hub) Flows
• Anything in master is deployable• To work on something new, create a
new named branch off master and push it remotely
• After signoff, merge it to master (via a Jenkins job!)
The Monster Exercise
MODULE 7: WHERE TO FROM HERE?
Now you know the basics…
Useful Books & Videos
Useful Sites
• http://refcardz.dzone.com/refcardz/getting-started-git
• http://git-scm.com/book
• http://stackoverflow.com/questions/tagged/git
• http://try.github.com
Please Help Us Improve
• Please fill in a feedback card telling us how we can improve this experience
• We’d love a testimonial too
Thanks for Coming!
• Go forth and Git!