Getting started with Git !!

ACKNOWLEDGEMENT

Sagnik Bhattacharya, my bachmate from EE department , IIT Kanpur helped me create this documentation while we were working for AUV together. I thank him for his contribution to the article.

Introduction


The winter interval was used for workshops on various dimensions of our project 
and Git was one of the primary requisites. It has features useful for working in 
groups on a set of files, eg features for overall control and integration of various 
same or different working branches of work. In this documentation, all text appear
in the format of the current text, while any computer command appears like this:
computer - command

Overview


Git is a wildly-used version control system in for software development. It is a 
distributed revision control system with an emphasis on speed ,data integrity, 
and support for distributed, non-linear workflows. Git was initially designed and
 developed in 2005 by linux kernel developers for Linux kernel development.

To simplify the above rather formal definition we can say Git allows groups of 
people to work on the same documents (often code, in our case we are going 
to use it for designing too) at the same time, and without stepping on each other's
 toes. It's a distributed version control system.

To start


To start with we downloaded Git from the terminal by the command
sudo apt-get install git.
This created the required Git environment in our Linux distribution.
 It creates a /.git/ directory.

Then step by step we look into its various facilities and systems.

We start with the command
git init
which initialises Git to track files that  we are going to add to it. Then there is 
a command  git status
which initially gives output as this.


It actually shows all the tracked and untracked files  and initially there is no 
tracked file.

Now we create a test txt file to and add it to git then again use
git status
and see the change.



We created a file named auv.txt and added it to git by the command
git add <file_name>.
We can also use wild card addition like if we give command
git add '*.txt'
then all the files ending with.txt in the directory wll be added .Now git 
status shows the newly added tracked file in green colour.

Now to tell Git at what state to track the file we have to  commit it.
The command here is
git commit -m “<any_comment”>
It looks like this.

By now we are able to understand the facility that Git provides. That is, 
we can keep track of how far we have been on the right track in our work 
so debugging codes with git becomes highly efficient.

Git gives an ID to each commit using which we can always return to this stage 
even if we have gone ahead changing our files and made some mistake. 
We can always head back to safety which is ensured by git .
 The ID is numerical and in  the case below it is the one in the yellow colour!

Now one crucial thing should be mentioned . All the work we have been doing 
is in the master branch of our git repository. But git can give a tree structure
 working facility. We can create other branches or remove them or merge them
 with the master.

For working in a team we use a common git repository in www.github.com and 
there we create our own branches and work on our part of the system. When
 the final decision is taken we merge the desired branch to the master and thus 
we can build our main working tree. Other works or suggestions remain in the
 branches always for testing and for using as other options.

We can clone the master in our personal repositories and go on working with it.
To taste this topic of addition in Github refer to the following tutorials:

Tutorials for Git




An example Git workflow shown below :



I am not going to describe all the git commands and their usage as it is already 
done by the tutorials very efficiently. However, I feel responsible to mention one 
thing. While in our workshop we had a doubt about the term origin in the
 command
git remote add origin ..
and the command
git push origin ..
The confusion was whether origin is a key word or some kind of command 
argument . My personal observation was that origin is a marker which marks
 the point where my copy of code is going to pushed at the master branch.
 So, basically if we use something like
git remote add  abcd ..
along with
git push abcd ..
then also it works fine. I did it with my name and it is not origin :-) )



LIST OF USEFUL COMMANDS

Now for future convenience I am going to list a compilation of useful Git 
commands and their applications which may be helpful for future use of 
our project and for other people too:

add            Add file contents to the index
bisect         Find by binary search the change that introduced a bug
branch         List, create, or delete branches
checkout       Checkout a branch or paths to the working tree
clone          Clone a repository into a new directory
commit         Record changes to the repository
diff           Show changes between commits, commit and working tree, etc
fetch          Download objects and refs from another repository
grep           Print lines matching a pattern
init           Create an empty Git repository or reinitialize an existing one
log            Show commit logs
merge          Join two or more development histories together
mv             Move or rename a file, a directory, or a symlink
pull           Fetch from and integrate with another repository or a local branch
push           Update remote refs along with associated objects
rebase         Forward-port local commits to the updated upstream head
reset          Reset current HEAD to the specified state
rm             Remove files from the working tree and from the index
show           Show various types of objects
status         Show the working tree status
tag            Create, list, delete or verify a tag object signed with GPG

git help -a
and
git help -g
lists available subcommands and some
concept guides. See
git help <command>
or
git help <concept>
to read about a specific subcommand or concept.

With this I am going to conclude this report on Git  but before that I would 
like to say that Git can be used in Windows and other operating systems also. 
For our mechanical branch which used Solidworks and ANSYS 
(to be used in Windows environment), required Git in Windows for 
easy arrangement of work.



Comments