Back to Top

HAROLD'S BLOG

githubAN INTRODUCTION TO GITHUB

If you are new to programming, you may not be familiar with Git and GitHub. Git is a version-control software which was invented by Linus Torvalds, the main developer behind the Linux kernel, back in 2005.

The main roles of Git are to help people keep track of project revisions, and to allow team collaboration. Several persons can work at the same project independently, and Git will make sure that all the code snippets are merged in perfect harmony.

On the other hand, if something goes wrong, it is very easy to revert to any of the previous project versions. Or, if one of the developers decides to test a new feature, the project can be branched off without affecting other people's work.

To get started, you will need to download a copy of the software, which is available for the Windows, Mac OS X and Linux/Unix platforms. Here's the download link: https://git-scm.com/downloads

To make things work, Git uses repositories, also known as "repos". A repo is just a fancy name for a collection of files and folders (source code, images, videos, etc.) which are tracked using Git.

You can host your repositories locally or use an online service. While storing projects locally has its advantages, my strong recommendation is to choose a cloud-based repo storage service.

The most popular repository hosting platform is GitHub. You can create a free account here: https://github.com/. But why is GitHub so useful? Let us assume that you work with another software developer on the same project, and both of you want to save your work simultaneously. It's clear that one of you will lose his/her work, right? With GitHub that can never happen, because the centralized repository system will document and organize all the changes.

Beginners to Git and GitHub may find the system a bit overwhelming, but Microsoft provides an aptly named "Hello World" tutorial which allows anyone to work with repositories, branches, commits, and pull requests. Here's the link to the tutorial: https://guides.github.com/activities/hello-world/

These are some of the most important Git/GitHub terms that developers should be familiar with.

- A "commit" is a snapshot of your work which is saved to a locally stored repository (for now). Coders commit to repositories, the way you save the files that are associated with a project you're working on to the hard drive.

- "Push" sends the locally stored commit to the cloud, synchronizing the data. Developers who work offline can create several commits, and then, when they have Internet access, push them all to the GitHub servers.

- A "branch" is derived from the main codebase. If your repo is a tree, its trunk is called the "master branch", and its branches are called... "branches", what else? Let's assume that you plan to add a third-party payment solution to your application; you'd branch off the trunk/master branch, and then test several providers, only keeping the ones that integrate nicely with your project. Or, if the idea can't be implemented properly, you can switch back to the previous version.

- If a branch works fine, you can "merge" it into the master branch, making it a part of the main codebase. And if you decide to branch off in the future, the recently merged code will be included as well.

- When you create a "clone", you are copying an entire repository locally. Why would you want to do that? Well, maybe you have replaced your computer with a newer, faster one, for example.

- Any developer may want to create a "fork" every now and then. Forks are similar with clones, but they are often used to copy other people's work. Perhaps you like a project which has been developed by somebody else, and you want to take it into a new direction. In this case, your fork gives you the power to edit and/or improve another person's open source project without making any changes to the original code.

- Once that your work is done, you can submit a "pull request"; if it is accepted, your changes will be merged into the master branch.