Signup/Sign In

How to use git in linux

Posted in Tricks   LAST UPDATED: MAY 31, 2021

    What is git?

    GitHub built by the contributions of developers all across the globe. It is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It is also a Source Code Management System (SCMS) which a track that changes the file also allows reverting to any change. It is one of the most efficient platforms for some of the world's best projects. It helps individuals interested in building or developing projects and to recognize in the open-source community.

    Why is git needed?

    There are so many languages and frameworks!! Why should one learn git?

    The reasons to learn git:

    1. Track changes to your code:

    Tracking changes to your own code is very important. It allows you to maintain different versions of the same software and makes sure you lose no code and recover it at any point in time.

    1. Save your code to the cloud
    2. It supports large developers community and online websites to upload your source codes or get other source codes to make your work easier
    3. Lots of software available for both who comfortable with command line and for others GUI tools

    How does it work?

    When you committing, or saving the state of your project, or change something in your files, Git takes a snapshot of the entire system and saves a reference to it. In a sentence to say it functions as a series of snapshots for your file system.

    This article is a quick setup guide for installing and using GitHub and how to perform its various functions.

    Installing and Configuring Git:

    To get started, visit and download the suitable version that supports your operating system.

    Run the below command in the terminal to install it.

    $ sudo apt-get install git

    Configuring GitHub

    Once the installation has successfully completed, the next thing is to set up the configuration details of the GitHub user.

    After running the installation, open Git bash and run these commands.

    $ git config --global "studytonight"
    $ git config --global

    To do this, use the following two commands by replacing studytonight with your GitHub username and replacing with the email id you used to create your GitHub account.

    Creating a local repository

    To create a local repository, create a folder on your system which will be pushed to the GitHub website.

    Run the following command:

    $ git init Mytest

    So here, Mytest is the folder that is created and "init" makes the folder a GitHub repository. If the local repository is created successfully, then you will get the following line:

    $ Initialized empty Git repository in /home/studytonight/Mytest/.git/

    Adding repository files to an index

    Adding repository files to an index is an important step. Here we push important things onto the website into an index.

    Let's create a file that contains a simple C program and save it as add.c.

    int main()
       int a,b,c;

    Now add it to the index with the following command:

    $ git add add.c

    Once all the files are added, we can commit it by the following command

    $ git commit -m

    Some Useful Git Commands

    The following are some useful Github commands to work on.

    $ git add text.txt

    This command adds the files created and edited to the staging area.

     $ git push origin master

    If you want to place your project somewhere on the cloud where your teammates can access it. The second command pushes the files we have on the master branch to the origin repository.

    $ git clone "link of the remote repository"

    we use the command git clone "url of the repository" to Just navigate to the place where you want to clone the repository and run.

    $  git merge

    The git merge command, which is going to help us bring the changes on the same file by different teammates of yours and merge them into our files.

    We can also fetch the changes first by using the $ git fetch command and then merge them into the files we have.

    $ git fetch --all

    This will fetch all the commits that we don’t currently have. This could help you analyze your workflow.


    Version control is an important requirement of almost all software engineering be it a developer or a learner for their daily practice. It’s a tool that you’ll definitely found helpful and I hope you have got a basic knowledge of it.

    Published by: MounikaDasa