Skip to content

A simple guide to Git

rictic edited this page Sep 13, 2010 · 12 revisions

Install Git, if you haven’t already.

Click “Fork project” on the Git page for this repository. This will create a new page and a fork of the project just for you.

Then clone your repository like so:
git clone git@github.com:[your username goes here]/Mario-AI-Competition-2009.git

To register yourself with Git:
git config --global user.name "Firstname Lastname" # your username is fine too git config --global user.email <you@domain.tld>

Working locally:
git status # check what’s changed, what branch you're on, etc git diff # see the differences between your files and the current branch git add file1 file2 # add files that you have created or changed git rm file1 # delete a file git committ -m “message” # include a message summarizing your changes or we will send koopa troopas to your house

Pushing changes:
git push origin # publishes your commits so far to your fork

Fetching changes:
#Suppose you want to fetch rictic's repository at git://github.com/rictic/Mario-AI-Competition-2009.git git remote add rictic git@github.com:rictic/Mario-AI-Competition-2009.git # add a remote repository named "rictic" at that url

#then you can pull in changes like so:
git pull rictic master # pull changes from rictic’s master branch into your current branch

#note that you can’t have any uncommitted changes in your current branch when you merge in. If you do, you can just use git’s temporary storage area, the stash
git stash # saves all of your uncommitted changes
git merge rictic # merges in rictic’s changes
git stash pop # re-applies the changes that you saved

Troubleshooting

Q: How do I pull from a repo now that they’re private?

A: You’re using a non-authenticated clone url (begins with git://) you need to switch to an authenticated one (begins with git@). The easiest way to do this is to edit your .git/config file, and change the beginning of the appropriate url from git:// to git@ (don’t worry about breaking anything, you won’t).

More info: the cheat sheet