Lately I was challenged and given an assignment to consume some source code hosted on GitHub and contribute to it by performing few given tasks. I, being pretty new to Git spent few hours over internet and trying to figure out how does this thing work. I had no prior knowledge on it and given the fact that of my past experience has been on Microsoft technologies I was actually little scared. 🙂
But, let me tell you, i felt much better when i completed that challenge. Although I must admit that despite being a simple challenge it was still daunting to me.
Anyways, I felt that it would be kind of nice to share my experience and may be help others to understand about git.
What is Git?
Git is an open source project that has a great community support and a solid user base. If you are an open source developer then Git is probably a first class requirement for you. Based on your use, it can be free of cost to you.
Hey ! But what exactly is git and why would somebody use it? Good question !
Git is probably the widely used version control system in today’s computer world. It is used more than other popular ones in the league, like TFS, SVN.
Few reasons for its popularity:
Git has a great support for distributed development. Rather than everything pointing back to a central code repository, Git allows each developer to have their own local repository where all their code changes and commits with full history are maintained. Since you are going to be working locally in your own repository, you can work in a disconnected mode and still commit files and push all of your commits to server using a simple push command in one go. Isn’t that a great feature?
During my challenge I used GitHub which is a code hosting platform to store my code files. See this Hello World example to understand more about GitHub tool but in short it lets you create repositories, create branches and merge them. You will need to create an account on GitHub to perform these operations.
GitHub allows you to access various public repos available. You can make your own copies from them by forking out and start to contribute. When you create a new repository it is accessible at a web url (see example below) which makes it so easier to be shared with someone else:
Fork a repo
Fork is basically a copy of a repository. You can either create a blank repository or fork (read as copy) out an existing repository. This feature makes it so easier to have something in place to begin with and not work from scratch. This also allows you to work independently in your own copy without impacting the original repository. You can find links to tons of existing repository and contribute here.
Later on when you are done with your changes/fixes you can collaborate with the owner of the original repository by issuing ‘Pull Requests’ to the owner. I consider ‘Pull Request’ to be like a code review exercise and if your changes are approved then these can be merged into the original repository by the owner. You can also set notifications using ‘Watch’ and you will be notified whenever an action is performed on your pull request.
It is always a good idea to provide a solid documentation for your project. This helps others to understand and contribute to your project in much better way. When you create a new repository a master branch is created for you automatically. This branch contains a blank file called README.md (.md is a short for markdown). You can use this file to provide some documentation about what your project is and what current branch contains. For more information on how to format the markdown file, follow this link.
But readme.md files are generally kept short and concise. If you wish to produce more detailed and long form content about your project then you can put that information on wiki for your repository.
I hope this article was informative. Apart from these concepts, I would also like to share how to setup a git repo locally and talk about few git commands at windows command prompt. I will explain more in Quick Intro to Git – Part II.