SlideShare a Scribd company logo
Switching to Git
Using branches and pull requests
What’s the goal?
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)
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)
But how often has this happened?
Too much going on

Release
r100

Release
r101

r102

r103
What if we could ...

Release Release
r103

r100

Release Release
r102

r101
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.
Turns out, we are not alone in having
this issue ...
... and there’s already a (better/best)
practice
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
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
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
Clone the repository
•

Grab a copy of the repository (only once)

$ cd ~/Sites/
$ git clone git@github.com/youruser/yourapp.git
Cloning into ‘yourapp’ ...
Create a branch
•

When you start a specific task, every time

$
*
$
$
*

git branch -l
master
git checkout -b bug/5012-fix-oauth
git branch -l
bug/5012-fix-oauth
master
Make changes
•

Do the work, commit it (and amend if
needed)
$ 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”
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 git@github.com:youruser/yourapp.git
06ff761..b3ea751 bug/5012-fix-oauth -> bug/5012-fix-oauth
Open a pull request
•

A pull request is used for integration or
feedback
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”
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
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).
Wait, what about forks?
Not necessary

Stolen from http://zachholman.com/talk/how-github-uses-github-to-build-github/
Pulling upstream changes
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(-)
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.
A few tools to make the process easier
github/hub
•

Wrapper that shortens git commands for
GitHub
GitHub for Mac
•

Yes, there is a GUI, but learn to use the CLI
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
That’s it.
Ad

More Related Content

What's hot (20)

Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
Carl Brown
 
Git 101
Git 101Git 101
Git 101
Sachet Mittal
 
Git
GitGit
Git
Shinu Suresh
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
Jim Yeh
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
Behzad Altaf
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
Arthur Shvetsov
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
Dilum Navanjana
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
jstack
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
Mack Hardy
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Git workflows
Git workflowsGit workflows
Git workflows
Sergiu Savva
 
Git collaboration
Git collaborationGit collaboration
Git collaboration
Pham Quy (Jack)
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Roland Emmanuel Salunga
 
Route service-pcf-techmeetup
Route service-pcf-techmeetupRoute service-pcf-techmeetup
Route service-pcf-techmeetup
Gwenn Etourneau
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
Fran García
 
An introduction to Git and GitFlow
An introduction to Git and GitFlowAn introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
Carl Brown
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
Jim Yeh
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
Behzad Altaf
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
Arthur Shvetsov
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
Dilum Navanjana
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
jstack
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
Mack Hardy
 
Route service-pcf-techmeetup
Route service-pcf-techmeetupRoute service-pcf-techmeetup
Route service-pcf-techmeetup
Gwenn Etourneau
 
An introduction to Git and GitFlow
An introduction to Git and GitFlowAn introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
 

Similar to Switching to Git (20)

git Technologies
git Technologiesgit Technologies
git Technologies
Hirantha Pradeep
 
Working with Git
Working with GitWorking with Git
Working with Git
Tony Hillerson
 
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Mark Hamstra
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
Victor Wong
 
Git
GitGit
Git
Mayank Patel
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
Betclic Everest Group Tech Team
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
Alberto Leal
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
Pranesh Vittal
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
.Git for WordPress Developers
.Git for WordPress Developers.Git for WordPress Developers
.Git for WordPress Developers
mpvanwinkle
 
Git hub
Git hubGit hub
Git hub
Nitin Goel
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Version Control Systems Software Engineering
Version Control Systems Software EngineeringVersion Control Systems Software Engineering
Version Control Systems Software Engineering
ssuser1c86e3
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
Sebin Benjamin
 
3 Git
3 Git3 Git
3 Git
Fabio Fumarola
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Git github
Git githubGit github
Git github
Anurag Deb
 
Git for developers
Git for developersGit for developers
Git for developers
Hacen Dadda
 
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Dev, Staging & Production Workflow with Gitify (at MODXpo 2015 in Munich)
Mark Hamstra
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
Victor Wong
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
.Git for WordPress Developers
.Git for WordPress Developers.Git for WordPress Developers
.Git for WordPress Developers
mpvanwinkle
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Version Control Systems Software Engineering
Version Control Systems Software EngineeringVersion Control Systems Software Engineering
Version Control Systems Software Engineering
ssuser1c86e3
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
Sebin Benjamin
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Git for developers
Git for developersGit for developers
Git for developers
Hacen Dadda
 
Ad

Recently uploaded (20)

Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Ad

Switching to Git

  • 1. Switching to Git Using branches and pull requests
  • 3. 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)
  • 4. 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)
  • 5. But how often has this happened?
  • 6. Too much going on Release r100 Release r101 r102 r103
  • 7. What if we could ... Release Release r103 r100 Release Release r102 r101
  • 8. 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.
  • 9. Turns out, we are not alone in having this issue ...
  • 10. ... and there’s already a (better/best) practice
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. Clone the repository • Grab a copy of the repository (only once) $ cd ~/Sites/ $ git clone [email protected]/youruser/yourapp.git Cloning into ‘yourapp’ ...
  • 15. Create a branch • When you start a specific task, every time $ * $ $ * git branch -l master git checkout -b bug/5012-fix-oauth git branch -l bug/5012-fix-oauth master
  • 16. Make changes • Do the work, commit it (and amend if needed) $ 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”
  • 17. 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
  • 18. Open a pull request • A pull request is used for integration or feedback
  • 19. 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”
  • 20. 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
  • 21. 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).
  • 23. Not necessary Stolen from http://zachholman.com/talk/how-github-uses-github-to-build-github/
  • 25. 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(-)
  • 26. 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.
  • 27. A few tools to make the process easier
  • 28. github/hub • Wrapper that shortens git commands for GitHub
  • 29. GitHub for Mac • Yes, there is a GUI, but learn to use the CLI
  • 30. 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