Igor SantosWeb developer● From Rio de Janeiro, Brazil● PHP Developer for ~6 years● Ruby and JS Developer for fun● Playing around with git for ~2 yearsslideshare.net/igorsantos07
0. Introduction● Knows what Git is?● Have ever used Git in the command line?● Have ever deployed code?○ How? SCP? WGet?● Anyone developing in the production server?
1. Git Basics● Commit: Saves changes with a description● Pull: Get commits from a server● Push: Send commits to a server● Remotes○ A remote machine that has a copy of the repositoryand accepts your commits○ In a common centralized organization you usuallyhave one, but its possible to have many○ Example: main repo is BitBucket or Google Code,mirrored to GitHub
2. Configure your serverigor@local$ ssh firstname.lastname@example.org: **********santos@bluenose$ mkdir repossantos@bluenose$ cd repossantos@bluenose$ pwd/users/cs/santos/repossantos@bluenose$ git clone «repo» myRep --bareThis creates a clone of that repository that works just asanother repository: with all administrative data, but notuseable for development, as the code is not really checkedin - just the Git meta-data.Take note
igor@local$ cd dev/myCodeigor@local$ git remote add prodssh://email@example.com:/users/cs/santos/repos/myRepigor@local$ "Hi there!" > README.mkdigor@local$ git commit "+ Adding readme"igor@local$ git push prod2. Configure your serverName given to the remote serverComplete repository URLNo line break!
igor@local$ git commit "+ Adding readme"igor@local$ git push prodQ: OK, so... wheres my README file?A: In the repository!Q: I cant see it. «not really a question»2. Configure your server
3. Git Hooks● 2 types: client and server hooks● Client:○ pre/post-commit○ [prepare-]commit-msg○ post-checkout, post-merge● Server:○ pre/post-receive Once per push○ update Once per pushed branchhttp://git-scm.com/book/en/Customizing-Git-Git-Hooks
3. Git HooksSimple copy$ cat hooks/post-receive#!/bin/shGIT_WORK_TREE=/var/www/mysite git checkout -fOpposite of git clone --bare: copies the entire repositorycode, without git data. By default does that with the masterbranch, but you can use other options here as well.GIT_WORK_TREE tells git where it would copy stuff.
4. Advanced ideasGitHub and other Git online repositorieshave options to do HTTP requests with codeinformation after pushes, similar to post-receive hooks. This data can be used totrigger a deployment script in the server.Theres also an online service calledDeployHQ, where you can configure anyrepository (SVN/Git/Hg) and many deploymethods (FTP/SFTP/S3/Rackspace).It deploys new code using the chosen method.