Github (https://www.github.com) is one of the most popular revision control system and source code management tool. It offers very simple user interface and has very good documentation. In this post we will talk about few of the most used features of Github along with a getting started guide for github beginners.
Why use Github ?
Revision control and source code management is one of the most important aspect of software development/programming in general. There are plenty of tools available for the same, most of us have used SVN a very popular revision control system, but Github is different, it's not just a revision control system, it offers a whole lot of functionalities, below are few of the most used Github functionalities which makes Github a very popular choice for software developers and IT organizations.
Integrated Issue Tracking.
Collaborative code review.
Team management using Organizations.
Text entry with Github flavored markdown. Autocomplete for stories and user names.
Linking stories with each other.
Milestones and labels.
Syntax highlighted code and data.
GUI Applications for PC's and Mobiles.
Including all of the above it's free for everyone to use with unlimited repositories, however you require a subscription plan if you wish to keep your repository private. For organizations who wish to host their data on their own infrastructure github provides a subscription/licence based solution which can be hosted on appropriate infrastructure.
In order to use Github you should have an active account at http://www.github.com, if you don't have one you can register for free. Once you setup your account refer below to start using Github for your next project:-
Download git for your machine, github has client available for almost all major OS so this should not be a problem until and unless you use something alien.
Login to Github and create a new repository, keep the repository name simple and easy to remeber. Don't forget to check the initialize with Readme option, or else you won't be able to clone the repository to your local machine.
Once you have a repository created go back to your machine and start git bash (A command line tool available with every git install)
Run below commands to setup user user name and email
Now go back to your repository and copy the repository url available in right sidebar, you will find two options here, one https and other ssh, I prefere https, you can use ssh as well once you setup ssh keys in your machine, for now use https.
Next go to directory of your choice and run below command to copy the repository in local.
git clone <-----repository url here----->
Now switch to the recently cloned directory. This will be the master branch of your repository. We will talk about branching later.
Next create few files, and when done run below command to add those file to your local git repo, Git uses a tracking mechanism to check added/modified/deleted files from the workspace.
(This will show the current status of the repository, with all the changes in local or remote branch in case there are multiple users using the same repository to commit code.)
Once you decide which file to add you can run below command to add the file to repository.. git add <---filenme here-->
or you can also add all the files using a single command as
git add .
Once you have added the file you would want to commit the file, but remember that commit here does not mean your file will be available at remote branch, instead commit adds the file to the local queue managed by Git for all the files which need to be pushed to remote branch. Use below command to commit you changes..
Every-time you change code or create a file you would like to add a comment for future reference and hence you have the option to put commit messages.
git commit -m "my first commit to my github repository"
Now you have comitted your code and it's time to push it to your remote repository. Use below command to do the same..
git push -u origin master
Now git will ask for a username/email or password, use your recently created username/email and password.
That's all now go back to github.com and see you repository. It should have the latest changes available. I have tried to cover the basics here, Git is very poweful and has a lot of other features, will try to cover them in next post. Don't forget to share your comments, suggestions and queries below. Happy coding.
About Vipin Dubey
A web developer, blogger, amateur designer and an open source enthusiast.