Why to choose Git Repository
There are numerous internet articles which will tell you difference
between Git and other popular repository system like subversion, CVS etc. But I
didn’t want to discuss comparison rather I will let you know what the benefits
Git can delivers to us, so that we can clearly make our mind whether to go for
Git. Below are some of benefits
- No Internet required to work on, you can work offline.
- Branching is a light weight process
- You can stack your uncommitted changes and can popup them once you are ready.
- More flexible workflow
- Data redundancy & replication
- Works well with open source project or projects where contributors may take months to contribute there code.
Let’s review
each of them in detail
No Internet
required to work on, you can work offline – First steps to use Git is to
create a local repo at your machine. You can use Git Clone command for the
same. Since you have a complete repo at local machine, we did not have to
bother about internet connection. We can access complete history or revision
and commit our changes. Once we get online and are ready to submit code then we
can push code to remote server. Here I want to brief you with terminology Push.
In Git operation commit is used to commit changes in Local repository and when
you want to commit your changes into the remote repository from where you have
cloned your Local repository you will be ‘Pushing’ your changes. The command
Push can be used for the same. Similarly for getting changes from remote
repository after clone operation you can use Pull operation.
Branching is
light weight process – We all know advantages of branches. In Git creation
of a branch is simply creating a Pointer. Git branching is so cheap that you
can create hundreds of branch in a day and can delete them. It’s always good to
work with branches so that main trunk will always be cleaner. In Git we can
merge even two branches which don’t have common ancestors. We will look more on
it in Branching and merging section.
Stash – In order to understand Git Stash feature lets
consider a scenario which we all had encountered some or other way. Let’s
consider that I am working on an issue1 and I am in middle of my changes.
Suddenly my manager comes in and asks me to quickly fix a production bug.
Unfortunately the changes required to fix production bug is in same file on
which I had changes for issue1. Since I am not done completely with issue1
coding, I can’t check In my code. But I want to fix production issue which
should be on latest code. One way is to backup file at our file system and
replaces workspace file with latest from repository and later on when we done
with Production changes we can copy backup file in to workspace.
Git provides us one easy way to do this as Stash. You can stash your
uncommitted changes in Git and later on can unstash your changes to continue
your work. In data source terminology you can push your uncommitted changes in
to a Stack using stash command and
later on can popup your changes. With stash command, Git will save your changes
and will replace workspace file with latest from repository. Later on when you
done with your critical issue fixing you can unstack your changes using apply
option of stash command.
More Flexible
Workflow (Stage/Index) – Working with repository we usually have below
workflow
1. Checkout/Update
files from repository
2. Modify files
for relevant changes
3. Commit file
back to repository
In Git one
more level/area is introduce before committing your changes. This area is known
as Stage/Index. You can consider
this level as an area where you are preparing your commit. Once you prepare
your commit you can move ahead for commit. Once you are done with your changes
then you need to add modified files to staging using add command.
$git add
<filename>
Adding a file
in staging is optional, You can use commit command with –a option to add a file
into staging and then committing. The command commit with –a option will merge
add and commit command.
Let’s consider
same scenario as above, we are working on an issue1 and we need to pause our
work to fix a production issue. This time changes required to fix production
issue is a subset of changes done for issue1. In other words we can say that
some of changes implemented for issue1 will be fixed production issue. But
committing a file means committing all changes/modifications in a file. We can’t able to select a set of changes
within a file to commit.
Git enable us
to do it using stage area. You can choose selected changes within a file and
can add them to staging area. Only changes added to staging area will be getting
committed. We can use Git add command in interactive mode.
Git provides
easy way to ignore files from tracking. It provides us fault tolerance as data
redundant on multiple machines. Other than above benefits, Git provide lot more
benefits which we can explore more when we actually start using Git.
Conclusion: Overall you will be benefited by
using Git. It provides lot more flexibility which I have not able to cover
above. There are lots of client tools available for Git to use like Tortiose
Git, SmartGit etc. For eclipse lovers there is a Egit plugin to make life
easier. There is only one disadvantage which I see with Git is about space
utilization. Since a complete repository is replicated on each developer’s
machine it will definitely not beneficial or effective in case you have limited
space. But in my opinion Data storage are so cheap now a days that it can be
easily overcome.
Comments
Post a Comment