Installing
Installing git is a fairly simple process:
- OS X - Follow these instructions
- Windows - Follow these instructions
- Linux - typically found in a package called 'git-core'
Starting Out
Each git repo is local to you. To create a repository, you simply tell git to initialize in the root directory of your game.
git init
Committing
To commit and save your progress, you first specify the files you wish to update using the 'add' command.
git add thisfile.java
You can use wildcards like you normally would in a command line.
git add *.java
After you have added each file, you can commit using the 'commit' command.
git commit -m "I fixed that bug where the player falls through the world."
Notice that we can specify a message explaining the changes with the (-m) argument.
Reverting
Sometimes, when your program worked well before and you've introduced a bug, it is nice to be able to revert changes.
To simply revert the file to the last one you've committed, simply use the 'checkout' command. You can specify a file.
git checkout thatfile.java
To revert to the last commit, just go to the root of your project and tell it to checkout that directory. Remember that '.' just means the current directory.
git checkout .
To revert a commit once you've committed, it's just a bit harder. You shouldn't have to do this since your commits should only be on working (that is, correct) changes. You simply use the 'revert' command. Here, HEAD is just a special word that indicates the last commit. It will normally merge with your current changes, which may not be what you want, so you might want to revert your uncommitted changes first (see above).
git revert HEAD
At the end of the competition, I will show you how to push to a remote repository on a website called github. Then, everybody can enjoy your game and learn from your code.