Git is a great tool for version control. If you write a little or a lot of code, it’s a good idea to keep track of changes you made. This is extremely useful, especially if you found a mistake and need to undo things. Git also allows you to creat branches which allows you to prototype without worrying about loosing your original, pre-prototyped work. Now, you can do this all without a version control system, but Git allows you to do this all within an organized framework. For example, you could easily just copy your source code to a new folder and try experimenting with a new idea, but if you do this a lot, eventually you will have many different folders, each with different code. In git, you can create branches instead, and only checkout or work on branches one at a time, so your digital workspace isn’t cluttered.
This guide is meant for those who work in the terminal. In particular, this is for anyone working within Linux (e.g. Ubuntu) or Max OS’s where the terminal is available by default. I haven’t used windows in almost a decade, but I’m sure there is a way to access the terminal (I’m not talking about the DOS window). I think you may be able to use Cygwin, but I am not 100 % sure. Anyways, now for the basic basic guide. For a more thorough guide, check out
http://learn.github.com/p/intro.html
which teaches you not only Git, but how to backup your code online with Github and use it thereafter.
Basic guide to Git
Initialize, add and commit
To use git, all you need to do is type in
git init
In the folder you want your version control system. Then, whenever you want to log and keep track of a change, you type in
git add .
git commit
The first command, git add ., stages the changes for git for all files in teh current directory (you can also add individual files or use the * notation). This essentially means that you are ready to commit or log the change. This is not a permanent thing. You can revert any changes at any time (keep reading below). The next command,git commit, actually logs or commits the change. As soon as you type this, the default text editor, e.g. vi, will open up. Write a brief description of the changes made and then save and quit. You can type
git log
To see a few of the last commits. Other useful commands are git status and git diff. You can also make changes to your previous commit by typing
git commit --amend
which is useful if you want to add or remove details about the commit. Also, if you commit without a description, it will not commit.
Read the rest of this entry »