Hi, I'm Chris Moyer's Blog.

Basic git for a Local Repo

I'm still not fully sold on git, but sometimes it's nice to set up version control for a single project. It's nice to be able to track what you've done, roll back experiments and otherwise protect your work (and sanity.) This is just an annotated account of this process for a small project I was doing with CakePHP, half to later refresh my memory and half for others doing the same.

> git init # create the in-place repo

> git add app # add files

> echo “.gitignore” >.gitignore # ignore some files
> echo “cake” » .gitignore
> echo “.htaccess” » .gitignore

> git branch working # create scratchpad

> git checkout working # start working on it.
Switched to branch “working”

  1. edit some files

> git status

  1. On branch working
  2. Changed but not updated:
  3. (use “git add …” to update what will be committed)
    #
  4. modified: app/controllers/events_controller.php
    #
    no changes added to commit (use “git add” and/or “git commit -a”)

> git add events_controller.php

  1. On branch working
  2. Changes to be committed:
  3. (use “git reset HEAD …” to unstage)
    #
  4. modified: app/controllers/events_controller.php
    #
  1. rinse and repeat until you're done with a chunk of work

> git commit -m”Bug fixes” # commit this set of changes to the working branch

> git diff ../maste # see what you changed

> git checkout master # head back to original
> git merge working # merge your changes in



Back to Blog Home »