I just recently picked up Git and I realized that there is
no simple way of explaining how to get started using Git so I decided to put together a VERY SIMPLE tutorial. (Check this video out, the best video tutorial I’ve found on how to get started with Git) And when I mean simple, I mean you can only do basic commands but it should help get you started. =] Sometimes in life, you just need that ”initial push”. Haha!…. To learn about pushing to a remote repository, check out github. It’s amazing.
You can download Git at: http://git-scm.com/ For those of you who don’t know what Git is, it’s basically an excellent open-source version control system. It’s especially helpful in collaborative projects but you can use it for yourself to keep track of different changes you make during a program’s life-cycle. Git lets you manage different “branches” of a project – let’s say for instance at any given point you have 2 different implementations in mind but you’re not sure which one is the best. At that point, you can create a branch to work on the 1st implementation and if that doesn’t work, you can simply back-track to the branching point and work on the 2nd implementation. Git essentially manages a tree-structure of your program wherein the “master branch” or “trunk” is your primary path and each node represents a “commit-point” of your project (You can think of commits as an image or snapshot of your project). After experimenting with multiple branches, you can simply merge different branches to put together your different implementations.
Ok, now for the tutorial to get you started…
- To create a git repository, navigate to the project directory (ex. cd ~/workspace/project_name) and use the command ’git init’
- When adding files to be monitored or “staged” by git, use ’git add filename1 filename2 ..’ or simply use ’git add .’ to add all files (notice the space followed by the period) if you want to index all of the new files
- To create a snapshot or a commit point, use ’git commit -m msg’ wherein ‘msg’ is the commit message. You can also use ‘git commit’ and you will be directed to a text editor where you can enter your commit message. Only files tracked via ’git add’ will be in that snapshot.
- To create a branch, use ’git branch branchname’. To switch between different branches use ’git checkout branchname’. To delete a branch use ’git branch -D branchname’
- If at the current branch you decide you want to merge it with the master branch, use ’git merge branchname’
- To obtain a graphical representation of your working tree, type in ’gitk’