Saturday, February 4, 2012

Setting up Git for my website

Just wanted to log the process of setting up the Git version control system for editing the code of my website.

  • Local Machine
    • Make a directory for your code
    • Run git init inside of it
    • Add some content and commit it
  • Server
    • Password stuff
      • Make an SSH public encryption key if you haven't already
        • ssh -t rsa -C 'someone@somewebsite.com'
        • Follow the instructions it spits out
        • Give a password if you want
      • ssh -p 2222 me@myserver.com 'mkdir -p .ssh'
        • You'll have to enter a password here
      • cat ~/.ssh/id_rsa.pub | ssh -p 2222 me@myserver.com 'cat >> .ssh/authorized_keys'
    • Git stuff
      • ssh -p 2222 me@myserver.com
      • cd public_html && mkdir website.git && cd website.git && git init --bare
      • cd hooks && cp post-receive.sample post-receive
      • echo 'GIT_WORK_TREE=/dir/where/you/want/to/store/code git checkout -f' >> post-receive
  • Local Machine
    • git remote add website ssh://ip.add.re.ss:portnumber/~/public_html/website.git
    • git push -u website +master:refs/heads/master && git push
Now, if I want to edit the code of my website on my local machine I can do so and have changes pushed to the website whenever I want to. I just have to be careful not to push breaking changes. Time to get intimate with Git branches!

No comments:

Post a Comment