Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active November 4, 2015 12:28
Show Gist options
  • Select an option

  • Save githubutilities/aebc146092faa57fd089 to your computer and use it in GitHub Desktop.

Select an option

Save githubutilities/aebc146092faa57fd089 to your computer and use it in GitHub Desktop.
Git push to deploy

Git Push to Deploy

  • init git server using git init --bare

  • edit hooks/post-receive, remember to chmod +x post-receive

#!/usr/bin/env ruby
# post-receive

# 1. Read STDIN (Format: "from_commit to_commit branch_name")
from, to, branch = ARGF.read.split " "

# 2. Only deploy if master branch was pushed
if (branch =~ /master$/) == nil
    puts "Received branch #{branch}, not deploying."
    exit
end

# 3. Copy files to deploy directory
deploy_to_dir = File.expand_path('../deploy')
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"

# 4.TODO: Deployment Tasks
# i.e.: Run Puppet Apply, Restart Daemons, etc

it basically checkout master branch with GIT_WORK_TREE pointing to the target directory for deploying

  • git clone <username>@<server-ip>:<path>

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment