On this tutorial, I will describe how you can start using git on windows environment as your preferred version control system. I am assuming, you have basic knowledge about version/revision control system already, and may already used other version control systems already so that you know what commit/checkout/merge etc means.
What Is GIT:
In professional development, source control are an important criteria to be fulfilled. Either you want to preserve the ability to resume back to an older stable code version of a project, or want to have the ability to work concurrently with other developers on same files with minimal overhead, you will need some kind of version control system implemented, for sure. There are many systems for this kind of tasks like, SVN, Perforce, Microsoft TFS etc. GIT is comparatively new addition to this list. But, it has become one of the most popular now a days because of its benefits over others. Specially, the slogan fits very well with its criteria, which is ‘Fast Version Control System’. I am going to introduce with very basic idea to start working with git version control system on windows environment.
Understanding Git For Other Version Control Users:
If you are already using visual studio with other version controls like SVN or Microsoft’s own team foundation server and not used git yet, you will have to think about git a little differently. All of these version control systems are centralized, which means, after doing works, when you commit something, goes directly to the central repository, usually hosted on a centralized/remote server.
Git Is DVCS:
Unlike other source control management system I mentioned above, GIT is distributed. That means, we can use it as a local repository and also host it to a server. Each cloned git repository contains full revision history synchronized withe others and can be treated as a complete repository anytime. So, if your server is destroyed, you won’t lose the revision tree for your repository, your local copy can be reinstalled on server and will act as the old repository exactly in the same way. You can create new branch/merge with a revision without being connected to central/remote repository as well.
Installing GIT On Windows:
You have to go to official git website. Just download the windows installer from download section and install. it’s that much easy!
You will get two different version to use, one is command line tool(known as ‘GIT Bash‘), another is GUI Tool(GIT GUI). However, GUI tool’s functionality is very limited. So, it’s better not to use that and stick with command line tool, after a little practices, it will become easy for you.
Setting Basic Configuration:
Git recommends to set up your name and email globally so that it can use those info with your commits on revision history. To do so, open the git bash tool and write the following two lines:
$ git config --global user.name "Your Name" $ git config --global user.email email@example.com
This is one time setup as you did it ‘globally’. It will work for any git repository that you will be creating in future.
Create And Initialization Of A Repository On GIT:
To create and initialize a repository, first you have to be on the directory you want to make as a repository. For this, you can re-use the ‘cd’ command line directive. Then, you have to run the initialization command. Additionally, you should configure your name/email on git global configuration for identification purpose. First, open GIT Bash tool. Write command statements as follows:
$ cd F:/MyProjectFolder $ git init
Remember, don’t try to use windows directory structure with backslash(‘F:\MyDirectory’), that won’t work here. ‘init’ command makes the directory as a git repository and creates its necessary core files/directories(hidden).
If you want to retrieve source from an existing repository(whether it’s on locally or remotely), use this command instead:
$ git clone path-to-repository
This will get the latest version of the codes to current git directory. In this case, you don’t need using ‘git init’ command.
Add Files To GIT Repository And Commit:
first you will have to run the ‘add’ command for the file(s) you want to add to repository. Then need to add a commit command. Here are code sample to add all files in the directory and commit them to git:
$ git add . $ git commit -m 'My First Commit'
You Should use comment for every commit. Remember, This commit will be made locally on your current git directory, nowhere else. If you have retrieved code from a remote repository and want have your commit as part of that, use the following additional command after the above ones:
$ git push origin master
This will upload the local changes/commits to the original git repository. In short, ‘git push’ would work as well in case you aren’t using multiple origins. If you created a local repository first and now want to upload/publish it to a remote repository, you can use command as below:
$ git add origin url-to-repo $ git push origin
Further Updates And Commit On GIT Repository:
It is also quite easy. You just have to run ‘add’,’commit’ and ‘push'(if applicable) command after every updates are done. The new commits will only take place for the files those are changed.
There are a lot more command options for more advance usage. I will suggest you to go through the git online book for learning more. Its free and very helpful. If you wish to host your project on a web server, you can should use github , which you can use either for public open source project(free of cost) and also private project(have to pay monthly fee). However, you can use assembla as well to get a free private repository up to 3 users.
Hope this small git tutorial on windows environment will help you in some extent for starting this amazing version control system which is now ruling the world of software development. Let me know if you have any comments/questions/suggestions. Happy coding 🙂