Lets Go GIT — Learning Simplified

Ghanshyam Varindani
6 min readJul 11, 2020
Lets go GIT- Learning Simplified

Today, there are numerous version control systems available in market but GIT is shinning above all. Let us see what the secret recipe GIT has which make it so popular. I will be using Gitlab for explaining key concepts. Idea behind writing story is to make learning simplified for all.

What is GIT?

Git is a distributed source control System and massively scalable. The system need not be decentralised. Operations for version management are local hence require limited internet access to merge with remote repository. The ability to perform local management make it very fast to work on.

What are the Key concepts of GIT?

As most of the work is performed local and internet access is required to merge the code in remote repository, GIT is distributed in two broader layers as Local and Remote. Local will have three states of GIT as Working, Staging and Repository.

GIT Life Cycle

Basic steps to start with GITLAB and Project(Repository) Setup

  1. How to create project?

First, create your sign in on GITLAB, https://gitlab.com. With successful login you would be able to see below screen

Login Page on gitlab

There are 3 ways of creating projects: Fresh Project, Existing Source Locally and Gitlab project(Fork and Clone). We will cover creating fresh project in this tutorial.

Fresh Project: Fresh project refer to creating new project on gitlab repo and adding files or codes on same. Brief series of steps to create fresh project is as below. You can clone the project on local repository and add files on git.

Prerequisite : freshproject.git should exist on gitlab under your username

git clone https://gitlab.com/ghanshyamvarindani/freshproject.git
cd freshproject
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing Source Locally: Assume you have code residing locally and you would like to add it to existing gitlab project. Below step will add files to project on gitlab. This can also be used if you are creating fresh project and want to move files first time. Remember, here folder you are working vs project name on gitlab need not be same.

Prerequisite: Existing folder refer to folder on your local machine. Remote_project is project available on gitlab where one want to move code.

cd existing_folder
git init
git remote add origin https://gitlab.com/ghanshyamvarindani/remote_project.git
git add .
git commit -m "Initial commit"
git push -u origin master

Git old Project to New Project: Below command will aid one to move existing repository to new repository.

Prerequisite: existing_repo should be project initialise on git. New_repo should be new project name on git.

cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/ghanshyamvarindani/new_repo.git
git push -u origin --all
git push -u origin --tags

Let usbegin and see series of steps in details for Your first project creation

Create New project also known as repository on Github, and enter relevant details as Project name, description and visibility level. For our example, we will create project “gitlabdemo”.

Project Creation Page

Once project is successfully created you will be able to see screen as below.

First View of Project

Once project is created on Gitlab, it is known as remote repository or project. We will be performing configuration setting on local to

On command prompt on Windows or Terminal on MAC, perform below steps

2. How to set configuration on local machine?

git version
git config — global user.name “<<your full name>>””
git config — global user.email “<<your email id>>”

Create project on your local machine with name of “projects”. Once done it would look like “/Users/<<your username>>/Desktop/projects”.

3. How to clone repository on local?

In order to add/modify files on remote repository one need to clone the project on local repository. When clone is clicked, one will be able to see clone with SSH and Clone with HTTPS option. For our demo, we will be using clone with HTTPS.

git clone https://gitlab.com/ghanshyamvarindani/gitlabdemo.git

Clone with HTTPS
Cloning to local machine in folder projects

Once successfully cloned you will be able to see folder in your local machine under projects folder. On placing command ls -al you will see below folders and files in view.

The .git folder contains all the information that is necessary for your project in version control and all the information about commits, remote repository address, etc. It also contains a log that stores your commit history so that you can roll back to history.

One can check the status of git with command “git status”. We can see our branch is on master, which is the only branch available at present

Check status with command “git status”

4. How to add files from local to remote repository?

Create text file on local as “sample.txt

echo “this is the file we would move to remote repository” >>sample.txt

Once file is created on can see status with command “git status”. Output states the file is created on working directory and not yet moved to local git repository

To add “sample.txt” to staging area, we have to use “git add” command. If specific files need to be added one can state the file name as suffix else “.”.

git add sample.txt

To commit to local repository directory, we have to use “git commit” command as “git commit -m “<<free text message>>

git commit -m “first sample file commit”

Once commit is done your changes are recorded on local repository. We can check status with “git status”

git status

Now, we have added our change to local repository, its time to merge with remote repository or project. It is best practice to first sync remote repository to local repository to view if any change has been made to remote repository before merge.

Follow below commands, “ git pull origin master”. Here origin states your local repository and master states remote repository

no changes are observed with git pull origin master

We observe here the origin repo is upto date as master hence one can proceed with merge using “git push origin master” command. Command prompt will request for username and password being used on gitlab before mege.

git push origin master

You would be able to see your file available on remote project now.

Project status post push to remote repo

We have covered here how to create project, add files to project with process of cloning, pull and push to master repository. These are basic commands of GIT can play handful for one looking forward to work on GIT.

I will be writing about advance topic soon.

--

--