Hopefully, you read our earlier post about Version Control and you have some idea what it is all about. I listed out a few problems of using the 'crude' form of version control.
Obviously, there is a fantastic solution to all that, and that is Git and Git for Windows. Let me first talk about my understanding of Git, and then move on to the Git for Windows tool. They are both two separate things that work together to help you with fantastic version control. Also, the concept of version control is not unique to Git. There are so many open source and self-hosted and hosted solutions of git that are available. Those things aren't really part of the discussion here and you should explore those later.
However, the general concepts of git and git for windows is what you would need for everyday usage from a developer perspective.
So, git is the software that enables complete version control. What does that 'complete' mean?
Create repositories – When you begin working with version control, you will hear about 'repo' or 'repository' or 'respositories' all too frequently. This repo is the folder where you have asked git to start monitoring. It could be pretty simple, like you have one folder which has just one html file. You create a repo at that folder, and git will start monitoring that one single file in that folder.
Monitor changes – git will constantly monitor the folder (and all files and subsequent folders and the files in them, recursively) for any changes that you make. You add a single line, or a single character and you bet the git has noticed it.
Commit changes – this is the best part about using git. Once you have made significant changes to your project and you want to safeguard this (like those compressed folders I talked about in the previous blog), you will do a commit. Further, when you commit, you have the option to write notes about why you are committing.
Push changes – ah! The confusion may come here. You see, when you commit changes, the changes have been noted, sort of a like telling git that you have reached a milestone. However, the real magic of backing up this code online happens when you push these changes. So, commit happens locally and a 'push' pushes these commits online.
Branches - this becomes useful when you are working as part of a team. There is usually something called as a main branch. Every commit goes by default to this main branch. However, if everybody is working on the same branch, that won't be nice at all. Ideally, each developer will work on his own branch (and make commits and pushes to indicate development progress) and keep his development effort separate from the rest.
Pull Request – A pull request is made when the developer (with his own branch) wants some of his commits to be integrated to the main branch. That is when the developer raises a pull request for his branch. Usually it is essential to include a reviewer in the pull request, so that another developer may review the pull request, look at the commits and then finally merge the code.
Merge the Branch – When the pull request (with all its commits) looks good, then the reviewer will merge this branch with that of the main branch. This means, when the next stage of the development starts, a new branch (with all the commits of all the developers and their branches and their commits that have been accepted) can be created by each developer and start working on the next phase of the project.
These are the cool stuff that git enables. There are probably more stuff it does but these are the ones that matter the most to me in my daily developer life.
Before I jump into 'git for windows', you need to understand something. Git needs to be installed on a server. This could be self-hosted (meaning you have your own server on which you install git) or hosted (you get git servers from another company like github or bit bucker or from a cloud service that comes bundled with git software such as Microsoft Azure or Amazon Web Services and so on). Once you have your own git server installed, you will be able to create projects, user accounts and the usual management stuff.
Of course, the development does not happen on the git server. The git server is that 'online' space where all your code (and its changes) are stored. You need something, a client for the server to interact with. There are dozens of clients that you can use and the one that I prefer is git for windows. As the name suggests, there is git for other platforms like Linux, Unix and other operating systems that support application development.
Next, I will create a simple project and run through all the git commands explaining all the different things that git can do, as described above. find that post here.
Git for windows, provides two ways to work with your git server. There is the 'git bash' and 'git GUI'. Although it is tempting to use the git GUI, I would forbid any up and coming developer to endure the 'learning curve' of using the command line version of git for windows, that is 'git bash'. It presents you with a unix/linux type command line interface with which you can do all the above stuff that you can do with git. Of course, git for windows also comes with shell integration so that you can git bash (or git GUI, but you should really not use the GUI git) on the folder you are planning to use with a simple right click.
Follow me on twitter, facebook and instagram for more updates. Thanks!