switching to git
DESCRIPTION
An abbreviated version of a presentation for my company's development team on the basics of Git and how we'll use Github to manage our process.TRANSCRIPT
![Page 1: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/1.jpg)
Switching to GitUsing branches and pull requests
![Page 2: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/2.jpg)
What’s the goal?
![Page 3: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/3.jpg)
Ship code that is ready for production often.
• Build software that we are confident in shipping
• Ship code more often to address needs
• Become better developers through industry standard practices (with fewer bad habits)
![Page 4: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/4.jpg)
Three kinds of tasks ...• Features (Add or change marketable
features)
• Bugs (Fix issues reported by users and staff)
• Hotfix (Fix very urgent issue with platform)
![Page 5: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/5.jpg)
But how often has this happened?
![Page 6: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/6.jpg)
Too much going on
Release Release
r100 r103 r101 r102
![Page 7: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/7.jpg)
What if we could ...
Release Release
r100 r103 r101 r102
Release Release
![Page 8: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/8.jpg)
You could make this work with subversion
• Create a branch for each task (feature, bug, hotfix)
• Reintegrate / release in whatever order is needed
• Slow process and lots of opportunity for errors.
![Page 9: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/9.jpg)
Turns out, we are not alone in having this issue ...
![Page 10: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/10.jpg)
... and there’s already a (better/best) practice
![Page 11: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/11.jpg)
Most Important Slide™• Anything in the master branch is deployable
• To work on something new, create a descriptively named branch off of master (e.g. feature/new-oauth2-scopes)
• Commit to that branch locally and regularly push your work to the same named branch on the server
• When you need feedback or help, or you think the branch is ready for merging, open a pull request.
• After someone else has reviewed and signed off on the feature, you can merge it into master
• Once it is merged and pushed to master, you can and should deploy immediately
Stolen from http://scottchacon.com/2011/08/31/github-flow.html
![Page 12: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/12.jpg)
What are git branches?• Files are blob objects in a database, stored
in .git/
• A branch is really just a pointer to those objects
• Switching branches is moving a pointer and replacing the files (milliseconds)
• Transparent to the file system
More on how it works at http://ftp.newartisans.com/pub/git.from.bottom.up.pdf
![Page 13: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/13.jpg)
What is master?• The production-ready branch
• Not the same thing as /trunk, other than it is what all branches use as a parent
• Git tags are created on code merged into master, and those are then deployed to production servers
![Page 14: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/14.jpg)
Clone the repository
$ cd ~/Sites/ $ git clone [email protected]/youruser/yourapp.git Cloning into ‘yourapp’ ...
• Grab a copy of the repository (only once)
![Page 15: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/15.jpg)
Create a branch
$ git branch -l * master $ git checkout -b bug/5012-fix-oauth $ git branch -l * bug/5012-fix-oauth master
• When you start a specific task, every time
![Page 16: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/16.jpg)
Make changes
$ git branch -l * bug/5012-fix-oauth master $ vim configuration/production.php $ git add configuration/production.php $ git commit -m “Fix OAuth secret for Twitter” $ vim configuration/production.php $ git add configuration/production.php $ git commit --amend -m “Fix OAuth secret for Twitter, fixes redmine #5012”
• Do the work, commit it (and amend if needed)
![Page 17: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/17.jpg)
Push branch commits• Push to a named branch in the repository
$ git status # On branch bug/5012-fix-oauth nothing to commit, working directory clean $ git push origin bug/5012-fix-oauth Counting objects: 46, done. Delta compression using up to 4 threads. Compressing objects: 100% (22/22), done. Writing objects: 100% (24/24), 3.83 KiB | 0 bytes/s, done. Total 24 (delta 17), reused 8 (delta 1) To [email protected]:youruser/yourapp.git 06ff761..b3ea751 bug/5012-fix-oauth -> bug/5012-fix-oauth
![Page 18: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/18.jpg)
Open a pull request• A pull request is used for integration or
feedback
![Page 19: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/19.jpg)
Discuss pull request, merge accepted• Each pull request is a candidate for inclusion
in master, or at least a discussion about best approach
• Even “good” pull requests might have multiple revisions
• False starts happen – branches are “cheap”
![Page 20: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/20.jpg)
Continuous integration testing• Pull requests will trigger a Jenkins build job and
add a contextual link to it within Github
• A “build” is a snapshot of the repository at a particular commit that is run through a testing regimen
• At minimum, committed files are run through linters and the results are reported back on the pull request via an API
![Page 21: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/21.jpg)
Cleaning up• Once a branch is merged, it can be deleted
$ git branch --merged bug/5012-fix-oauth $ git branch --no-merge * master feature/top-secret $ git branch -d bug/5012-fix-oauth Deleted branch bug/5012-fix-oauth (was a705432).
![Page 22: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/22.jpg)
Wait, what about forks?
![Page 23: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/23.jpg)
Not necessary
Stolen from http://zachholman.com/talk/how-github-uses-github-to-build-github/
![Page 24: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/24.jpg)
Pulling upstream changes
![Page 25: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/25.jpg)
Get upstream changes• Pick up changes in the master branch
• Merge from another fork/branch of changes
$ git pull origin master remote: Counting objects: 18, done. remote: Compressing objects: 100% (5/5), done. remote: Total 11 (delta 8), reused 9 (delta 6) Unpacking objects: 100% (11/11), done. From git://github.com/youruser/yourapp bfbb16f..75737c6 master -> origin/master Updating bfbb16f..75737c6 Fast-forward src/unit/engine/PhpunitTestEngine.php | 2 +- src/workflow/ArcanistUnitWorkflow.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
![Page 26: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/26.jpg)
Get another branch• Fetch all branches, checkout from origin
$ git fetch origin $ git checkout -b feature/acme origin/feature/acme remote: Counting objects: 18, done. remote: Compressing objects: 100% (5/5), done. remote: Total 11 (delta 8), reused 9 (delta 6) Unpacking objects: 100% (11/11), done.
![Page 27: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/27.jpg)
A few tools to make the process easier
![Page 28: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/28.jpg)
github/hub• Wrapper that shortens git commands for
GitHub
![Page 29: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/29.jpg)
GitHub for Mac• Yes, there is a GUI, but learn to use the CLI
![Page 30: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/30.jpg)
Quick recap• We’re switching to git to improve the code
review process and ship better code more often
• All code changes are done through pull requests and reviewed by appropriate developers
• Continuous integration testing framework through Jenkins works in tandem with pull requests
![Page 31: Switching to Git](https://reader034.vdocuments.us/reader034/viewer/2022052618/554a55ddb4c905572f8b4be8/html5/thumbnails/31.jpg)
That’s it.