Introduction to Git

Github is a web-based platform used for version control. Git simplifies the process of working with other people and makes it easy to collaborate on projects. Team members can work on files and easily merge their changes in with the master branch of the project. Git & GitHub skill has slowly made its way from preferred skills to must have skills in multiple job roles.

Motivation to use Git

By far, the most widely used modern version control system in the world today is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. A staggering number of software projects rely on Git for version control, including commercial projects as well as open source. Developers who have worked with Git are well represented in the pool of available software development talent and it works well on a wide range of operating systems and IDEs (Integrated Development Environments).

Having a distributed architecture, Git is an example of a DVCS (hence Distributed Version Control System). Rather than have only one single place for the full version history of the software as is common in once-popular version control systems like CVS or Subversion (also known as SVN), in Git, every developer’s working copy of the code is also a repository that can contain the full history of all changes.

In addition to being distributed, Git has been designed with performance, security and flexibility in mind.

Version Control System (VCS)

A version control system (VCS) allows you to track the history of a collection of files. It supports creating different versions of this collection. Each version captures a snapshot of the files at a certain point in time and the VCS allows you to switch between these versions. These versions are stored in a specific place, typically called a repository.

You may, for example, revert the collection of files to a state from 2 days ago. Or you may switch between versions of your files for experimental features. The process of creating different versions (snapshots) in the repository is depicted in the following graphic. Please note that this picture fits primarily to Git.

Git Repository

A repository is a storage space where your project lives. It can be local to a folder on your computer, or it can be a storage space on GitHub  or another online host. You can keep code files, text files, images or any kind of a file in a repository. A GitHub repository can also be used to store ideas, or any resources that you want to share. You need a GitHub repository when you have done some changes and are ready to be uploaded. This GitHub repository acts as your remote repository.

Adding to a Git repository via Staging and Committing

A local repository provides at least one collection of files which originate from a certain version of the repository. This collection of files is called the working tree. It corresponds to a checkout of one version of the repository with potential changes done by the user.

After modifying your working tree you need to perform the following two steps to persist these changes in your local repository:

  • You use the Git git add command to move those changes from the working directory to the staging area. Staging in Git refers to a phase which includes all the changes you want to include in the next commit.
  • Git does not save changes yet. You need to run the git commit command to move changes from the staging area to the local repository.

This process is depicted in the following graphic.

Git add

The Git add command moves changes to the staging area. Here is a basic example of using add:

git add <file>

Git moves all changes of <file> in the staging area to wait for the next commit. This example adds the entire <directory> to the staging area:

git add <directory>

During the Git add session, you can pick the changes you would like to commit. Before that, you need to start an interactive session:

git add -p

  • Use y to stage a specific portion.
  • Use n to ignore a specific portion.
  • Use s to divide the portion into smaller parts.
  • Use e to edit the portion manually.
  • Use q to exit the interactive session.

Git commit

Git commit command takes a snapshot representing the staged changes.

git commit

After running the Git commit command, you need to type in the description of the commit in the text editor. This Git commit example shows how you set the description with the commit function:

git commit -m "<message>"

Git push

Once you move the changes to the local repository by using Git commit command, you can use Git push to transfer them to a remote repository.

This example creates a local branch in the remote repository, including all specified commits and objects:

git push <name of remote server> <branch name>

The following example pushes changes even if it does not end in a non-fast-forward merge. Beginners should not use this option:

git push --force

This example adds all local branches to the indicated remote repository:

git push --all

The following example pushes all local tags to the remote:

git push --tags

Advantages of using GitHub

1. It makes it easy to contribute to your open source projects
To be honest, nearly every open-source project uses GitHub to manage their project. Using GitHub is free if your project is open source and includes a wiki and issue tracker that makes it easy to include more in-depth documentation and get feedback about your project. If you want to contribute, you just fork a project, make your changes and then send them a pull request using GitHub web interface.

2. Documentation
By using GitHub, you make it easier to get excellent documentation. Their help section and guides have articles for nearly any topic related to git that you can think of.

3. Showcase your work
Are you a developer and wishes to attract recruiters? GitHub is the best tool you can rely on for this. Today, when searching for new recruits for their project, most companies look into the GitHub profiles. If your profile is available, you will have a higher chance of being recruited even if you are not from a great university or college.

4. Markdown
Markdown allows you to use a simple text editor to write formatted documents. GitHub has revolutionized writing by channeling everything through Markdown: from the issue tracker, user comments, everything. With so many other programming languages to learn for setting up projects, it’s really a big benefit to have your content inputted in a format without having to learn yet another system.

5. GitHub is a repository
This was already mentioned before, but it’s important to note, GitHub is a repository.
What this means that it allows your work to get out there in front of the public. Moreover, GitHub is one of the largest coding communities around right now, so it’s wide exposure for your project.

6. Track changes in your code across versions
When multiple people collaborate on a project, it’s hard to keep track revisions—who changed what, when, and where those files are stored. GitHub takes care of this problem by keeping track of all the changes that have been pushed to the repository. Much like using Microsoft Word or Google Drive, you can have a version history of your code so that previous versions are not lost with every iteration.

7. Integration options
GitHub can integrate with common platforms such as Amazon and Google Cloud, services such as Code Climate to track your feedback, and can highlight syntax in over 200 different programming languages.

One thought on “Introduction to Git

Leave a comment

Design a site like this with WordPress.com
Get started