GIT – a widely used version control system
git is a widely used version control system with its flexibility and rich command sets .
Here covers three most basic and important functionalities in GIT .
i) Creating a new repository and committing
ii) working with branches
iii) Cloning and distributed working
Creating a new repository and committing
This is a basic operation in any version control system. Assume a scenario where you are creating a maths software using C .
now each project should have a name ( I will be speaking package , software, project and repo interchangeably )
let it be myCproject . now to create a new repo the steps are :
create a new directory of that project name
>> mkdir myCproject
get into the project and intialis it for git database
now your project is initialized and ready to accept files .
start coding some files and place it myCproject directory . eg ) add.c,mul.c,sub.c,div.c
now this files wont get added to git unless you add into it
>> git add .
>>git commit -a -m ” Your first commit “
now your first version of the software should be commited and you can check it by
>> git status
>> git whatchanged
whenever you perform more than one commit then use
>> git diff
to get the changes from first and second commits .
Working with branches :
now placing all files under single category may be tiresome . So we can group similiar files under a branch .
branch is something like a sub-repo
first create a new branch under which you are going to work
let us say math software needs a gui
>> git branch gui
this will create a branch named gui .. to see the list of branches in project you can use
>> git branch
by default git will be in branch named master .
to switch over to gui branch use
>> git checkout gui
now your workings will be placed under gui branch after changed dont forgot to commit
>> git commit -a -m ” commit from gui branch “
now to switch back to master branch use
>> git checkout master
to merge all the changes done by the branch gui to master use
>> git merge gui
and after merging if the branch is no more needed then delete it
>> git branch -d gui
Cloning and distributed working :
whenever more than one user works with a project then sharing should take place . say two user alice and bob .
bob wants the myCproject from alice . then bob should issue
>>git clone /home/alice/myCproject
now bob will get a copy of alice in his current directory
similiarly commit and add are done as
>> git add sub1.c
>> git commit -a -m ” commit from BOB “
to get the changes made by bob alice will pull bob and get the changes by
>> git pull /home/bob/myCprojects
Commands overview :
git init-db = initialsises the repository
git add file1 file2 file3 = adds the files to git repository
git commit -a = commits with the next version
git status = current status of files and branch name
git whatchanged = history of all versions
git diff = difference between previous and next version
git branch branch-name = creates a new branch
git branch = lists the all available branches
git checkout branch-name = switches to particular branch
git merge branch-name = merges with other branch
git branch -d branch-name = deletes unwanted branch
git clone repo-url = clones a existing project from other url
git pull repo-url = gets the changes from other repo