preamble
we’ll use git to facilitate the process of pushing code to the vm. because there’s a cardinal rule about not serving files from a repo, we’ll need to create a git host and use a githooks to update the web root when code is pushed to the repo. i’m using the terms hub and prime introduced by Joe Maller in his post A web-focused Git workflow.
i don’t have a cool picture of the concept, like Maller did, but here’s one of a cute red panda (credit: tambako) to set the mood before we get started:
ok, here we go:
terms
- prime is the copy of the repo accessible by the web server
- hub is the bare source of truth repository
- project refers to the prime/hub pair
- vm is the vmware vm running centos
- laptop is the development computer you ultimately want to push files from
environment
- mac os x 10.5.8
- vmware 2.0.5
- centos 5.4
- git 1.5.5.6
steps
- set up
- on the vm, install git as root:
yum install git - on the vm, create a user to handle git-related activity:
useradd git - on the vm, get its inet ip address using ifconfig:
ifconfig - on the vm, copy your rsa public key (you’ll be pushing git updates over ssh) from your laptop into the git user’s .ssh/authorize_keys file on the vm
- on the vm, make sure the correct permissions are set on the authorized_keys file and .ssh dir:
chmod 700 /home/git/.ssh; chmod 644 /home/git/.ssh/authorized_keys - on your laptop, run a sanity check by logging into the vm via public key. note: if you’re using an alternate ssh port and/or different pub key file name, define these in your laptop‘s .ssh/config file:
ssh git@{ip address} - on the vm, in /var/www/, as root, create a directory that git can push content to (note: if the dir isn’t owned by git or isn’t world-writable, git throws an “error: cannot open .git/FETCH_HEAD: Permission denied” error):
mkdir /var/www/git/; chown git:git /var/www/git/ - on the vm, cd into the /var/www/git/ directory and su to the git user:
cd /var/www/git/; su git
- on the vm, install git as root:
- create a new project
- on the vm, create a new directory {proj name} for the prime repo and cd into it:
mkdir proj; cd proj - on the vm, initialize a git repo:
git init - on the vm, create and add a file so we can clone prime later (git dissallows cloning an empty repo):
touch readme;
git add readme;
git commit -m ‘initial commit’
Note: if you haven’t already told git who you are, run:
git config user.email “example.com@domain.com”
git config user.name “example.com” - on the vm, define a remote repository for the soon-to-be-created hub:
git remote add origin /home/git/proj - on the vm, cd into git user’s home directory:
cd ~ - on the vm, create the hub repo by cloning the newly created repo using the –bare flag (that’s a double ‘-‘ before bare):
git clone –bare /var/www/git/proj - on the vm, create a post-update hook in the hub repo to update the web directory when an update is pushed. open /home/git/proj/hooks/post-update and add the following:
# jump into web dir cd /var/www/sites/example.com/ # w/o this, git throws "fatal: Not a git repository: '.'" error # ref: http://bit.ly/5lieqQ unset GIT_DIR # pull in the updates git pull origin master
- on the vm, create a new directory {proj name} for the prime repo and cd into it:
- start working
- on the laptop, open a terminal on whatever machine your going to develop on and clone the new host repo:
git clone git@{ip address}:proj - on the laptop, edit the readme file in the repo, check in the change and observe in the output the results of the hook-initiated pull
- on the laptop, view http://{ip address}/readme to confirm the new code is displaying
- on the laptop, open a terminal on whatever machine your going to develop on and clone the new host repo:
references
- A web-focused Git workflow
- linus torvald’s suggestion to use .ssh/config to define alternate port
- James Strachan’s helpful clarification on why we run unset GIT_DIR before git pull
One thought on “standard stack v1: git”
Comments are closed.