Author: Nicola Pietroluongo
Viewers: 2,020
Last month viewers: 123
Categories: PHP Tutorials
Even many developers that already use Git sometimes do not quite realize all the benefits it provides.
Read this article to learn about the most important advantages of using Git and how you can benefit from them to have greater quality in your software projects of any language.
Contents
Introduction
The Benefits of Working with Git
Working offline
Fast to Work With
Repositories Are Smaller
Moving or Adding files
Ignore Certain Files
Branches
Check the Status of Your Changes
Stash Branches
Cherry Pick Changes from Branches
Find version that Introduced a bug using Binary Search
Conclusion
Introduction
As you may be aware, Git is a version control software application created by Linus Torvalds (the creator of Linux) with the collaboration of many other developers.
A version control application keeps track of all the changes that you do in the files of your project. Every time you make changes to files of a project, you can push those changes to a repository. Other developers can pull your changes from the repository and continue to work with the improvements that you added to the project files.
There are many version control applications. This article focus on the benefits of using Git.
The Benefits of Working with Git
Working offline
Some version control applications popular in the past like CVS and SubVersion used the concept of central repository accessible somewhere in the network where all the changes needed to be commited.
Git uses the concept of local repository where you have a copy of the complete repository of your project. You can commit the changes you make to the files of your project to the local repository. So Git allows you to work completely offline, i.e. even when you do not have access to a remote repository.
Later you can synchronize or sharing the changes you made when you have online access to the remote repository.
Fast to Work With
Repositories Are Smaller
Moving or Adding files
If you want to move a file inside your repository Git automatically track the moves. This was not possible in old version control applications like CVS. Moving a file would typically require to create a new file and remove the old one, thus losing the changes history.
git add '*.php'
Ignore Certain Files
Sometimes you have files being generated by your project, like for instance log files or files generated by your IDE, that you do not want to store in project repository because they are not really part of your source code.
You can tell Git to ignore certain files in the local repository directories using a file named .gitignore. The files listed in .gitignore are excluded from the version control process as if they are not there. You can share those rules committing the file or just keep it locally.
Branches
Sometimes you need to work on new experimental features without interfering with the main code of your project.
You can achieve this by creating new branches to try the code of those experimental features.
Branches also allow different developers to work on different features without interfering with each other work. Then when the features are ready, they can merge the branch changes in the main branch.
Check the Status of Your Changes
Check the status of the changes you made to your repository is pretty straightforward. The git status command lets you see what would happen if you committed your changes at a given moment. It can help to avoid the mistakes of using different externals branches of your project.
Stash Branches
If you are working on a branch of your project but you do not want to commit the changes, you can save the current status of that branch to return to it in the future. You can switch your work to another branch and insert the stashed modification in it.
Cherry Pick Changes from Branches
Find version that Introduced a bug using Binary Search
If you have an issue in your code and you want to know when it was introduced and what it is, with the git bisect command you could go back to every commit till you will find the bad one one which the issue was introduced. You can learn more about this on the documentation about Git tools for debugging.
Conclusion
In this part of the article we learned about some important features of Git that benefit your project development process and often are advantages when comparing to other version control applications.
In the next part we will cover more advance features that Git provides like collaboration between developers, using existing Web platforms that support Git and migrating repositories from other version control systems.
If you liked this article or you have questions about the topics covered here, post a comment here.
You need to be a registered user or login to post a comment
Login Immediately with your account on:
Comments:
1. complement - Aneet Kukreja (2015-08-20 23:32)
good one!... - 1 reply
Read the whole comment and replies
2. superb - tinashe zulu (2015-08-20 23:31)
learnt a lot... - 1 reply
Read the whole comment and replies
3. Fossil another alternative - Jeff (2015-08-20 20:23)
Fossil does most of what is mentioned and provides more features... - 0 replies
Read the whole comment and replies