Version Control using Git

Isaac Miti
Developer Circle Lusaka
6 min readNov 28, 2018

Sometime in December 2017, I attended a meet up at a local developer community Developer Circles Lusaka, at the end of the meetup one of the members started talking about the importance of using Version Control and contributing to Open Source.

I had heard of version control and had a GitHub account but I really didn’t know how to use them. With some research and a few Google searches, some reading here and there I was up and running with version control and GitHub.

You might have heard or come across the words version control and git or GitHub. By the time you finish reading this article, you’ll know what they are and how to use them.

What is version control?

“A component of software configuration management, version control, also known as revision control or source control, is the management of changes to documents, computer programs, large websites, and other collections of information.” — Wikipedia

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. Version Control shows you exactly how snapshots differed from the previous one.

  • An example of a Version Control System (VCS) is Git, Mercurial, SVN.

Why use version control?

You might be wondering why you should be using version control when you are just working alone on projects and/or on your local machine only. Well, version control can be some for some of the following reasons below but not limited to;

  • Collaboration: without a version control in place, you normally would be working in a shared folder with the same set of files, which is prone to errors. With version control system, everybody gets to work freely on any file any time.
  • Storing Versions: version control is used to store versions of your projects properly. It helps you keep track of changes to your project in a proper organized way.
  • Restoring Previous Versions: Being able to restore older versions of a file or an entire project, should you want to revert to a previous stable version.

How does version control work?

You might be thinking, “how exactly does version control work”. Below is

An illustration of how version control works

It lets you save a snapshot of your complete project at any time you want.

Your VCS shows you exactly how snapshots differed from the previous one.

Image Source

Version Control is independent of the type of project you are working on.

It does not care which set of tools you use, text editor, IDE, or graphical tools.

Types of Version Control Systems

There are mainly three types of version control systems names; local, centralized and decentralised. Images below illustrate local and centralized version control systems.

Local VCS
Centralized VCS

What to keep in mind

  • VCS is not a backup or deployment system.
  • Version Control is not a replacement for your backup system. You still need your back system, for the reason, VCS is for the purpose of recording changes you make to a project.
  • In order to back up, you have to commit changes and backup manually or pushing to a remote server known as a repository(repo), on platforms such as GitHub.
  • Version Control is not a deployment tool. When it comes to project deployment, you need deployment tools such as Heroku CLI for deploying a Node application to Heroku servers.

Basically, that’s what version control is and how it works and what it is not. Now we move to our second part. What Git is and how to use it.

What is Git?

As a developer or someone who reads tech news, you must have heard of Git or come across it somewhere somehow. If you haven't then continue reading.

Git (/ɡɪt/) is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. As a distributed revision control system, it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

Git runs on POSIX: Linux, Windows, macOS.

How to install Git

In order to install Git visit this URL https://git-scm.com/downloads

You’ll be presented with the screen above, the screen screenshot was taken from a windows machine, the download for windows is the default in the image.

Installation on Windows

Click the download button on https://git-scm.com/downloads and once the download is complete, simply run the .exe file and follow the prompts as illustrated below.

Screen 1: Windows Explorer integration.

On this screen make sure, Windows Explorer integration is ticked in the case for some reason it’s not by default.

This step is important on Windows as the context menu is your best friend when developing using this platform.

Leave the rest as defaults and move to the next screen.

Screen 2: Adding environment variable.

Here you have to leave “Use Git from the Windows Command Prompt” selected. The reason being, Windows Command Prompt has elevated privileges and it can work anywhere within Windows.

These two screens are the most important parts. Leave the rest as defaults and your installation should be done.

Up and Running with Git

Once the installation is complete, run the following command in your terminal or cmd to test if everything is working fine.

$ git --version

It should display git version number as illustrated below

Configuration

$ git config --global user.name "your name"

The command above sets the name you want attached to your commits

$ git config --global user.email "your email"

The command above sets the email you want attached to your commits

Creating Repositories

$ git init

When you run the above command in a directory, it initializes an empty repository

$ git init [project-name]

This creates a local repository with the name of your choice.

Making Changes

$ git status

This shows you the status of your repository

$ git add .

This adds all files in a directory

$ git add [file]

This adds a specified file

$ git add *[file extension]

This adds files using a wild card, like “.html” adds all html files

$ git commit -m "Commit message"

This records a snapshot of your project at a point in time permanently into your version history.

$ git clone [url]

This clones a repository onto your local machine from a remote repository.

$ git push -u [alias][branch]

Uploads your local branch commits to GitHub.

GitHub

Now that you have an understanding of version control and git. It’s time you created an account on GitHub and start using it as early as possible.

Sign up page.

Conclusion.

This article was an introduction to what version control and git is. I have included some of the most basic and essential git commands to get you up and running using git on your projects. It does not end there, there is more to version control and git, which I’ll write about in part two of this article. Thanks for taking your time to read this.

Git is awesome, Source

--

--

Isaac Miti
Developer Circle Lusaka

Love Code | Developer | Middle ages history lover | Carefree personality, life is what you make of it.