Erik's blog

Code, notes, recipes, general musings

Posts Tagged ‘git

standard stack v1: git

with one comment

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

  1. set up
    1. on the vm, install git as root:
      yum install git
    2. on the vm, create a user to handle git-related activity:
      useradd git
    3. on the vm, get its inet ip address using ifconfig:
      ifconfig
    4. 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
    5. 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
    6. 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}
    7. 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/
    8. on the vm, cd into the /var/www/git/ directory and su to the git user:
      cd /var/www/git/; su git
  2. create a new project
    1. on the vm, create a new directory {proj name} for the prime repo and cd into it:
      mkdir proj; cd proj
    2. on the vm, initialize a git repo:
      git init
    3. 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”
    4. on the vm, define a remote repository for the soon-to-be-created hub:
      git remote add origin /home/git/proj
    5. on the vm, cd into git user’s home directory:
      cd ~
    6. 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
    7. 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
              
  3. start working
    1. 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
    2. 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
    3. on the laptop, view http://{ip address}/readme to confirm the new code is displaying

references

Advertisements

Written by Erik

January 2, 2010 at 11:46 pm

Posted in tutorial

Tagged with ,

steps for merging changes from a remote clone of a git repo

leave a comment »

I’m a fan of github, but I don’t know how to apply changes made to a clone of my repo, usually announced via a pull request. The goal of this post, then, is to define these steps. Note: the steps below pulled in the changes as desired, but also auto-committed them despite the —no-commit flag, so these steps need refinement.

prereq

  • a git repo named origin
  • committer has issued a pull request. For this example, I’ll use a committer named FooBaz

steps

  1. add commiter’s repo as a remote
    • copy clone url for pull requester’s repo, eg git://github.com/FooBaz/yql-tables.git
    • define remote repo: git remote add FooBaz git://github.com/FooBaz/yql-tables.git
    • view list of remotes as sanity check: git remote show
  2. pull in FooBaz’s changes:
    • run: git pull --no-commit FooBaz master
    • note: this actually committed the changes for me 😐
  3. push changes to origin repo: git push origin master

ref

Written by Erik

December 24, 2009 at 11:43 am

Posted in tutorial

Tagged with ,