2. Igor Santos
Web developer
● From Rio de Janeiro, Brazil
● PHP Developer for ~6 years
● Ruby and JS Developer for fun
● Playing around with git for ~2 years
slideshare.net/igorsantos07
3. 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?
4. 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 repository
and accepts your commits
○ In a common centralized organization you usually
have one, but it's possible to have many
○ Example: main repo is BitBucket or Google Code,
mirrored to GitHub
5. 2. Configure your server
igor@local$ ssh santos@bluenose.cs.dal.ca
password: **********
santos@bluenose$ mkdir repos
santos@bluenose$ cd repos
santos@bluenose$ pwd
/users/cs/santos/repos
santos@bluenose$ git clone «repo» myRep --bare
This creates a clone of that repository that works just as
another repository: with all administrative data, but not
useable for development, as the code is not really checked
in - just the Git meta-data.
Take note
6. igor@local$ cd dev/myCode
igor@local$ git remote add prod
ssh://santos@bluenose.cs.dal.ca:/users/cs/santos/repos/myRep
igor@local$ "Hi there!" > README.mkd
igor@local$ git commit "+ Adding readme"
igor@local$ git push prod
2. Configure your server
Name given to the remote server
Complete repository URL
No line break!
7. igor@local$ git commit "+ Adding readme"
igor@local$ git push prod
Q: OK, so... where's my README file?
A: In the repository!
Q: I can't see it. «not really a question»
2. Configure your server
8. 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 branch
http://git-scm.com/book/en/Customizing-Git-Git-Hooks
9. 3. Git Hooks
Simple copy
$ cat hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/mysite git checkout -f
Opposite of git clone --bare: copies the entire repository
code, without git data. By default does that with the master
branch, but you can use other options here as well.
GIT_WORK_TREE tells git where it would copy stuff.
11. 4. Advanced ideas
GitHub and other Git online repositories
have options to do HTTP requests with code
information after pushes, similar to post-
receive hooks. This data can be used to
trigger a deployment script in the server.
There's also an online service called
DeployHQ, where you can configure any
repository (SVN/Git/Hg) and many deploy
methods (FTP/SFTP/S3/Rackspace).
It deploys new code using the chosen method.