Basics of GIT | Part 1

Git is a version control system that is used  to track and manage changes in files among multiple people or groups. Although its original purpose was to manage the source code in software development process, now it is also being used to keep trace of changes in any kind of files. Git is in fact a fully fledged system that could help to trace changes in files by creating complete history in one single computer or could be used in distributed nature via client – server architecture. It was first developed by Linus Torvalds in 2005, however currently it is being maintained by Junio Hamano. Refer to wikipedia for details on git history.

Git has become one of the indispensable tool for anyone either working with day to day data files or programmers working single or in a group. Therefore, this note is a personal reference of mine on using the basic commands available in git for version control.

Step – 1: Install git either using sudo apt-get install git for ubuntu (usually most linux systems support git by default). For windows system download the binaries.

git init |create repository

Initially, in order to work with git, we would need to create a repository. This is done with git init command in the working directory.  Once the command is success, We could check the status by git status command. However, it is to be noted that, this repository could be local or remote. If you have git repository in github or anyother server, those repository could be added by git remote add <name><remote address> . Also if we want to clone the repository from the open source community, then we could issue git clone command to clone the remote repository to the local working directory.

Examples:

> git init 
> git remote add origin https://github.com/dipakgaire/minst_classification.git
> git clone https://github.com/dipakgaire/minst_classification.git

git add | staging local files

After we create repository, the next step would be to add some files so that git could keep track of those files. To do so, first we add files to its index (staging area). We issue git add <filename>  command or git add * to add a file or all files in the given folder to the git index.

Examples:

> git add index.css
> git add *.css
> git add myfirststory.txt
> git add gitblogpost.docx

git commit | store changes

Once the file are added to the index (staging area), they are not register to the repository unless we commit them.  To commit our staged changes we issue git commit -m “messages”  command to store our changes. Note that -m argument in the command is for message.  Beside this, the history of our activities could be viewed by git log command.

Example:


> git commit -m “additional changes in html body tag”
> git log

git push | pushing local changes remotely

Push command redirects git to push our commit to the original repository in the server. To do this we need to add our remote repository using the command git remote add origin<remote_repository.git>. Once we are done, we could push our changes with git push origin master. If we included parameter -u after git push in the first attempt, after that we can simply use git push to push changes to the remote server.

git pull | pull from server, update and merge

Pull command is used to pull down any changes from the remote host, updated and modified by other members of the group or project. To pull any new changes git pull origin master could be issued.

…continued in part – 2