AN INTRODUCTION TO VERSION CONTROL

Photo by Mohammad Rahmani on Unsplash

Install Git

You need to install git on your machine. To do so, you can head to the official website to download the client for your operating system. Windows, Linux based operating systems and Mac OS are all supported.

Basic Configurations

Before setting out to use git, you need to configure it on your machine. There are 2 important attributes that you need to set — username and email. To configure your system, you can issue the following commands.

git config --global user.name '<username>'git config --global user.email '<email>'

Cloning a repository

Cloning a repository is the process of pulling a remote copy of a repository into your local machine. By a remote copy, we mean a repository that is hosted in code repositories like Github or Bitbucket.

git clone https://github.com/<username>/<repository_name>.git

Creating a Repository

A repository contains all your project files and keeps track of all the changes made on the files.

git init

Staging Files

Staging a file means that you are preparing it for a commit. To stage a file, use the command below.

git add filename.filename-extension
git add .

Committing Changes

In the spirit of version control, it is important to tell what happened in a certain stage. This is achieved by committing the staged files. Your commit message needs to be descriptive.

git commit -m "a descriptive commit message goes here"

Add Origin — Optional

To this point, we are working on our repository locally. If we want to push our code to a remote repository, the local copy needs to know where to push to. This is what is referred to as an origin.

git remote add origin https://github.com/<username>/<reponame>.git

Push Code To Remote Repository

The final step is to push your code to the remote repository. To do so, key in the following command.

git push
git push -u origin <branchname>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brian Kitunda

Brian Kitunda

Computer Science student Maseno University, Kenya