Git is version control software. You can think of git to be the equivalent of saving a document in a program like Word that keeps track of every version of your work, and allows you to share those versions with other people and collaborate in a way that won’t have you overwriting each other’s changes.
There are many alternatives to git, but it has become a standard for developers in large part because of github.com, a service for hosting code using git.
download / install: http://git-scm.com/downloads
If you are using a Mac, you can install using homebrew:
brew install git
For more information about homebrew, check out the project’s homepage: brew.sh.
On Debian/Ubuntu, install using apt-get:
apt-get install git
For Windows machines, download git from the git website: git-scm.com/downloads
Here are some basics of using git:
Create a git repository:
cd name-of-folder git init
git add name-of-file // or add all files in directory: git add .
When you add files to a git repository they are “staged” and ready to be committed.
git rm name-of-file // force removal of files: git rm -rf name-of-file-or-directory
Commit files and add a message using the
git commit -m 'a message describing the commit'
Create a branch:
git branch name-of-branch
Checkout a branch:
git checkout name-of-branch
Shortcut for creating a new branch and checking it out:
git checkout -b name-of-branch
Merge a branch into the master branch:
git checkout master git merge name-of-branch
Add a remote repository:
git remote add origin firstname.lastname@example.org:yourname/projectname.git
List associated repositories:
git remote -v
Pull changes from a remote repository:
git pull origin master
Push changes to a remote repository
git push origin master
Checkout a remote branch:
git checkout -t origin/haml
This interactive tutorial is a great introduction to both git and GitHub. Highly recommended.
I often refer to gitready.com for various tips and tricks for using git.
The help section of GitHub’s site has instructions for using github.com, but it also has some great documentation for using git.