Wednesday, February 23, 2011

Fast Version Control with GIT for total beginners

The first thing that you need before start programming anything you need to use GIT. maybe its problem for those who don't like to use commands but if you learn to use GIT you will find it very useful.

The purpose of GIT is to keep a sort of backup for the code that you write and everytime you change it Git keeps everything on track! so if you write new code or you want to experiment with your existing project then you can do all this without worrying that you will mess things up, because you can restore back the project as it was before thanks to GIT.

There are other version control programms the most powerful and the fastes programm is GIT.

Lets start using it!

First of all you need to install GIT, if you have a Linux OS then do it this way:
sudo apt-get install git-core

or if you have Windows OS then you can download it by following this link:
http://code.google.com/p/msysgit

First thing you need to do after you install GIT is to register your self to GIT by typing this commands:
 
git config --global user.name "username goes here"
git config --global user.email "your email goes here"
for example: 
git config --global user.name "Shpetim Islami"
git config --global user.email "Shpetim.islami@gmail.com" 
then make a new Repository, and you can do this by typing this commands:

cd [with this command you need to navigate to the folder where your project is or where you want to start the new project]

for example if you have xampp installed:  
cd C:
cd xampp
cd htdocs
cd [here the name of the folder where your project is]

and now you will be in the folder where your project is, and now you need to initiate a new repository by typing the following command:

git init

and now you will need to create a branch (a branch is somehow a version of your project, for each version of your project you can have branch), you make new branch by typing this:

git branch [here you should write the name of the branch, you choose it doesnt metter]
for example: git branch version1

You can choose which files to track by doing this:

git add [the file name goes here]
for example: git add index.php

If you want to see all the files in the project just type in:

git status

then you will see a tree of all files in your project folder.
Ok, now maybe you will write some codes, make your work... NOW WHAT?
well... now you have to the same steps by opening the Git (I assume you have closed GIT before) and navigate to your project with the cd command, then git status and you then git will show you the files that you have modified, deleted or added new ones. Now to save your work you need to make commit to your changes, you can do this by entering this in your command prompt(shell/terminal):

git commit -am 'here you can put an message anything you want'
for example: git commit -am 'fixed the problem with the navigation' 

and now you can go and relax or continue with your work, and now you know that if you make any mistake you can restore back the code (we will talk about this later on..).
If you have made a lot of commits for some project and you want to see the history and everything you have done from the beggining then all you have to do is type in:

gitk


and new window will pop up and there you will see everything you need or want to know (I think this doesnt need more explination)



[This was was part 1 of GIT for total beginners and there is a lot more what GIT can do! stay tuned for upcoming parts...]






No comments:

Post a Comment