This article is targeted towards developers, designers, managers, creative writers and all type of audiences that are working or planning to work on any individual or organizational project.
This article will help you get a basic understanding about Version Control Systems, Git and also give you a technical walk-through for GitHub explaining it’s architecture, workflow, feature and important commands and their uses. So, anybody who is already or is planning to start using Git for version controlling of their project, will get benefited from it.
GitHub is an online hosting service for version control using Git. It is mostly used for computer code and creative writing. It offers all of the Distributed Version Control System DVCs and Source Code Management SCM functionality of Git along with its own features and facilities.
In this definition of GitHub, we have come across two major terms, version control and Git. To fully understand how GitHub operates, what its functionalities and most importantly why it is used, you need to have a basic understanding of both Version Control System (VCS) and GIT.
What is Version Control
Version control software allows the user to have “versions” of a project, which show changes that were made to the code over time, and allows a user to backtrack, if necessary, and undo those changes.
If you are a Developer or a web designer and want to keep every version of a file, Version Control System (VCS) is a very wise thing to use. It allows you to revert selected files or even your entire project back to a previous state, compare changes over time, see who last modified something, who introduced an issue and when, and much more. Using a VCS also generally means that if you mess up or lose files, you can easily recover.
Local Version Control Systems
Many people keep copies of files in another directory perhaps a time-stamped directory for better storage and control so that they can maintain versions of their projects in their own local machines. This approach is very common because it is so simple, but it is also incredibly error-prone. It is easy to forget, which directory you’re in and accidentally writes to the wrong file or copy over files what you don’t want to.
To deal with this problem, programmers developed local Version Control Systems that had a database where they can keep all the changes in a file under revision control. One of the most popular version control tools was a system called RCS, which is still distributed with many computers today.
Centralized Version Control Systems
The next major problem people encountered was that they needed to collaborate with developers on other systems. To deal with this problem, Centralized Version Control Systems (CVCSs) was developed. All versions of your project are stored on a central server, and individual developers checkout and upload change back to this server.
This setup offers many advantages, especially over local version control systems. For example, everybody knows to a certain level what everyone else is doing on the project. Also, the administration over a single server was much easier as compared to local databases on every client’s machine.
However, this system still had its downsides like a single point of failure and others.
Distributed Version Control Systems
Distributed Version control system means, every collaborator has a local repository of the project in his/her local machine unlike central, where team members should have an internet connection to update their work, every time, to a main central repository.
Since every client fully mirrored the repository, hence, the greatest benefit was if any server dies, any of the client repositories can be used to restore the server because these systems were in great collaboration via that server. Every clone is actually a full backup of all data.
What is Git
Git can be defined as a distributed version control system that tracks changes in source code in progress for software development. It is designed for coordinating work among developers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano.
Git has other competitors like Subversion and Perforce but the major difference between them is Git stores and thinks about information in a very different way, and understanding these differences will help you while using it.
Conceptually, most of these different systems store information as a listing of file-based changes. These systems think of the information they store as a set of files and the changes made to each file over time.
Instead, Git thinks about its data more like a series of snapshots of a miniature file system. With Git, every time you commit or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
This is an important distinction between Git and nearly all other VCSs. That’s what makes Git more like a mini file system with some incredibly powerful tools built on top of it, rather than simply a VCS.
Some of the most famous applications and web hosting services that use Git are;
1. Strong support for non-linear development
2. Distributed development
3. Compatibility with existing systems/protocol
4. Efficient handling of large projects
5. Data Assurance
6. Automatic Garbage Collection
7. Periodic explicit object packing
Go to github.com and then signup by entering the required user credentials asked on the site, choose a plan as per your requirements like an open repository or a personal or a repository for an organization.
Now Start by creating a repository, start by giving a repository name, description and select the visibility and accessibility mode for the repository.
You need to install Git on your system. You can install Git on your system using either a package manager or an installer or from any other source. All instructions are listed at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.
Next, you need to integrate your project with Git. This can be done by cloning from the existing repository or by running the command ‘git init ‘ in command line under your project directory.
How Git Works
1. A Git repository is a key-value pair object store, where all objects are indexed by their SHA-1 hash value.
2. All commits and files are different types of objects living in this repository.
3. A Git repository is a large hash table with no possibility for hash collisions.
4. Git specifically works by taking “snapshots” of files
Now before you start working on GitHub you need to know about some concepts of Git like it’s architecture, staging, branching and much more.
It consists of 4 parts:
1. Working directory: This is your local directory where you make the project and make changes to it. A file is here when it is modified.
2. Staging Area (or index): This is an area where you first need to put your project before committing. This is used for code review by other team members. A file is here, when it is staged for the changes to be committed.
3. Local Repository: This is your local repository on your system, where you commit changes to the project before pushing them to the central repository on Github. This is what, provided by any distributed version control system. This corresponds to the .git folder in our directory. A file is here, when it is committed to the local repository and ready to be pushed to the remote repository.
4. Central Repository: This is the repository of the original project/product on the central server, a copy of which, is with every contributor as a local repository. At this point, all the committed changes are pushed to the remote repository.
The above image helps to get a better understanding of the different stages in a Git development cycle. Also, it shows the action required to move from one stage to another.
Branching In Git
Git Follows the concept of branching, where everything is done in branches. It has a main branch called the master branch, where all the code and branches are merged. The code on this master branch is supposed to be the final product of your project. That’s why, it is also very crucial to treat and manage this branch very carefully.
The core idea behind Branching is that all feature development should take place in a branch dedicated only to this feature instead of the master branch. In other Version Control System tools, this is somewhat an expensive process and often requires one to create a new copy of the source code directory, which could take a large amount of time for large projects.
Now, whenever you are working on a new feature, you diverge a new branch from the master branch, do the necessary changes and then merge the functionality back to the master branch. This helps in many ways as any broken code never reached the master branch.
Also, it leverages for a pull request to hold a discussion regarding a branch before merging to the master. Branching is one of the major features of Git and its lightness considered remarkable.
Cloning and Forking in GitHub
Cloning is done to create a local repository of your project on your machine so that you can start working on it and start contributing to the project.
Forking is about, when you want to contribute to someone else’s project. Or maybe you’d like to use someone’s project as a starting point for your own.
Creating a fork is actually having a personal copy of somebody else’s project. Forks act like a bridge between the original repository and your personal copy. You can submit Pull Request, if you want to offer your changes and contribute to other’s project and thus helping them to make it better. In GitHub, Forking is the core of social coding
GitHub important commands:
|Title||Git Command||Git Task|
|Configure Tooling||Configure user information for all local repositories|
|$ git config –global user.name “[name]”||Sets the name what you want attached to your commit transactions|
|$ git config –global user.email “[email address]”||Sets the email what you want attached to your commit transactions|
|Create Repositories||Start a new repository or obtain one from an existing URL|
|$ git init [project-name]||Creates a new local repository with the specified name|
|$ git clone [url]||Downloads a project and its entire version history|
|Make Changes||Review edits and craft a commit transaction|
|$ git status||Lists all new or modified files to be committed|
|$ git diff||Shows file differences not yet staged|
|$ git add [file]||Snapshots the file in preparation for versioning|
|$ git diff –staged||Shows file differences between staging and the last file version|
|$ git reset [file]||Unstages the file, but preserve its contents|
|$ git commit -m “[descriptive message]”||Records file snapshots permanently in version history|
|Group Changes||Name a series of commits and combine completed efforts|
|$ git branch||Lists all local branches in the current repository|
|$ git branch [branch-name]||Creates a new branch|
|$ git checkout [branch-name]||Switches to the specified branch and updates the working directory|
|$ git merge [branch]||Combines the specified branch’s history into the current branch|
|$ git branch -d [branch-name]||Deletes the specified branch|
|Review History||Browse and inspect the evolution of project files|
|$ git log||Lists version history for the current branch|
|$ git log –follow [file]||Lists version history for a file, including renames|
|$ git diff [first-branch]…[second-branch]||Shows content differences between two branches|
|$ git show [commit]||Outputs metadata and content changes of the specific commit|
|Redo Commits||Erase mistakes and craft replacement history|
|$ git reset [commit]||Undoes all commits after [commit], preserving changes locally|
|$ git reset –hard [commit]||Discards all history and changes back to the specific commit|
|Save Fragments||Shelve and restore incomplete changes|
|$ git stash||Temporarily stores all modified tracked files|
|$ git stash apply||Restores the most recently stashed files|
|$ git stash list||Lists all stashed changesets|
|$ git stash drop||Discards the most recently stashed changeset|
|Synchronize Changes||Register a repository bookmark and exchange version history|
|$ git fetch [bookmark]||Downloads all history from the repository bookmark|
|$ git merge [bookmark]/[branch]||Combines bookmark’s branch into current local branch|
|$ git push [alias] [branch]||Uploads all local branch commits to GitHub|
|$ git pull||Downloads bookmark history and incorporates changes|
|Remote Tracking||Connect to a remote repository|
|$ git remote -v||List all currently configured remote repositories:|
|git remote add origin <server>||If you haven’t connected your local repository to a remote server, add the server to be able to push to it:|
Companies and Projects Using GIT
—-> GitHub is being used by tech giants like Microsoft, Google, Facebook, Twitter, LinkedIn, Netflix and many others.
—-> Also, GitHub is used by open source projects like jQuery, Ruby On Rails, Perl, Debian & Linux Kernel.
Vishal Solanki is a Full-Stack developer in QSS Technosoft. He has hands on experience in technologies like ReactJS, GraphQL, SQL, Experimental Java & Android. He is always keen to learn and explore new things whether it’s technology related or something fun and weird.
QSS Technosoft has a proven track executing enterprise level web and mobile applications for its esteemed customers. QSS has a test center of excellence with a dedicated and experienced team of QAengineers.