wordpress development: tracking your code with version control
DESCRIPTION
Slides from the 2011 Reno-Tahoe WordCamp covering why developers should be using some kind of Version Control System and what models are currently being used in the industry.TRANSCRIPT
WordPress Development: Tracking your code with Version Control
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
What is Version Control?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
I can haz apple?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Apple Version 1Apple Version 2
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
v13v12 v14
v15 v16 v17
v18 v19 v20
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
• Where do we keep track of it all?
• What if we want to go back to a previous version because there's a worm in the apple?!
• Who put the worm in there and Why?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
In a nutshell...here's the magic:
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Today
2 Weeks Ago
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
With the right tool, you can do AWESOME things.
• Incremental changes?No problem!
• Revert to previous versions. DONE.
Track the reasons for changes as well as the owner of the changes.
It allows for easier code review and maintenance!
Cool huh?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
How can we apply these this newly acquired swag to
WordPress?
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
"Enterprise-class centralized version control for the masses"
ApacheCentralized version control systems are designed with the intent that there is One True Source that is Blessed, and therefore Good. All developers work (checkout) from that source, and then add (commit) their changes, which then become similarly Blessed. The only real difference between the tools current available is in the workflow, performance, and integration that each tool offers.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Distributed version control systems are designed with the intent that one repository is as good as any other, and that merges from one repository to another are just another form of communication. Any semantic value as to which repository should be trusted is imposed from the outside by process, not by the tool itself.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
We don't need to use that!
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Wait...WordPress uses Subversion...why are we talking about GIT?
Each solve their own problem!Subversion is fine for developing with WordPress!Using GIT is also a great idea!They each offer their own solutions to problems!
Depending on your project, one might work for you better!
Git is not better than Subversion. It is not worse. It's different.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Using Subversion with WordPress
Get the code!> svn co http://core.svn.wordpress.org/trunk/
Make changes!
Then when you're done you can see what you changed:> svn diff Turn your changes into a patch!> svn diff > my-patch.txt
Always check to see if changes have been made with:> svn status
Add your changes to the repository:> svn commit Get the latest changes from the repository:> svn update
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Awesome!I can fix bugs!Add features!
Solve world hunger!
You bet you can! But...there's some things you should know.
Most of you will not have authorization to make changes to the WordPress core. It's a CVS and only certain people can "bless" code.
You have to create a patch, then send it to a developer capable of blessing the code, then they have to apply it.
The same procedure has to be followed if you're going to share your code with someone else.
Inherited Workflow
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
But wait!
With GIT you can get all of the WordPress code! Make changes to it with equality.
You can then make changes...commit them...deploy them to your own repository as well as sending them to OTHER developers!
Then ... when you're ready - you can open a ticket for WordPress Developers - and attach a patch for them to review.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Using GIT with WordPress
Get the code!People have mirrored the Subversion code onto GitHub!> git clone git://github.com/dxw/wordpress.git
Make changes!
Then when you're done you can see what you changed:> git diff Turn your changes into a patch!> git diff > my-patch.txt
Always check to see if changes have been made with:> git status
Get the latest changes from the repository:> git pull Add your changes to the repository:> git add . > git commit
Send your changes to another repository:> git push another-repository master
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
How this can benefit you directly.
• WordPress core update comes out: For some reason your site breaks.
With version control, as soon as you realize that something has gone wrong you can roll back to the previous version which was stable in one command.
• An update for a plugin comes out and it's no longer compatible with your version of PHP.
Once again, the problem goes from "whoops" to "whew". You can roll back the code to any point and time until your environment supports this update.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
How this can benefit you directly.
• A theme is updated and it's no longer standards compliant.
You create a patch to fix the issue and send it off to the developer. You've now collaborated on the project, and with the right tool - you can look up all the changes that you've contributed.
• Your server get's hacked and you want to know if they touched any of the code on the server.
You run one command and see that status of your code to make sure that it hasn't been tampered with.• You've found a security hole in WordPress (core,plugin or theme) and right away
you create a patch to get it fixed immediately on your server.You can send this fix out to other developers or other installs in a way where they can apply it quickly and efficiently.
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo
Reno-Tahoe WordCamp 2011 Sterling Hamilton | http://sterlinghamilton.com | @sterlo