Git

Resources for Learning

http://alistapart.com/article/git-the-safety-net-for-your-projects

https://www.atlassian.com/git/

Github has a basic GUI client. I don’t like it one bit. Atlassian has SourceTree, which is freaking awesome. That said, once you get used to the CLI, using your terminal is going to be the fast most of the time.

Concepts

Configuration

Specificity Location of Config File Command
System Level /etc/gitconfig git config --system
User Level ~/.gitconfig git config --global
Project Level ~/Sites/yourWeb/.git/config git config

User Level is where you will typically be interacting with.

Caution: I have aliased Sublime Text, and have it in my path, which is why this works. If you have trouble, you can also do the alias, which is the first line.

Default editor

To set the default editor to Sublime, do this:

ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin
git config --global core.editor 'sublime --wait'

Basic Commands

git init [directory]

Creates a new repo in your current directory (or in the directory specified by the optional [directory] parameter.)

Edge Case: If you are creating a repo that you intend to be the “central” repo, use the --bare flag. That will not give the repo a “working directory” effectively makes it impossible to edit and commit directly in that repo.

git clone repo [directory]

Makes a copy of the given repository. Git will create a new folder using the name of the project. Optionally, you can specify the name of the directory (this will not create a new sub-folder within it, so this is good if you want to use a different name than the original folder name).

git status

Show files that are modified or staged.

git add -A

Add all modified files to the stage. This is usually done right before you want to commit.

git commit

Saves all files in the stage to the repo.

git commit --append

Allows you to fix-up the last commit (only do this if you have not pushed to a remote server). You can add/remove files from the commit, or simply change the commit message.