DEV Community

Avinash Reddy Arutla
Avinash Reddy Arutla

Posted on

Getting started with Git


  • Basic Linux commands
  • Able to navigate directories using terminal

So what is Git?

  • Git is a DVCS that stores the data in a filesystem made up of snapshots. These snapshots are created when the commit command is used.

What is a DVCS?

  • Version Control snapshots the present code along with the changes when committed. These snapshots can later be retrieved in case any errors creep in.

  • In Distributed Version Control System, the same snapshots created by the Version control, are distributed among the authenticated users.

  • When the need arises to merge everything to a single codebase, these snapshots can be merged fast and effortlessly.

Happy minions

How to Git??

  • Git, natively is a set of command line utility programs that are designed to execute on Unix based Operating Systems.

  • There are various other implementations of GIT as GUI, but the the full functionality of GIT is only through the CLI.

Installing Git

Linux/Unix users

  • Open your terminal, and install Homebrew with the following command

Homebrew installation Command

  • Now install Git

Install Git - Homebrew

Windows users

  • Go to Git Downloads, download the portable or the executable.

  • After the installation is complete, open Git Bash.

  • From now on, it's the same for both platforms.

Working with Git on a CLI

  • Executing git will list out all the available git commands which can be permutated accordingly. Image description

git init

  • Initialising a Git repository
  • Now, let us tell Git who we are Git Config details
  • Here,Avinash and you can place your name and email address. These parameters are used in commit history, and we will understand about commits further.

Git Config list

  • The above command will list all the globally defined parameters in Git.
  • Now lets initialise a git repository
  • I chose a folder named git_chicha for creating a git repository. Git init
  • Ohh, was that a mistake, now we'll remove git from the folder

Git remove

  • Now, we'll will create a file inside the git repository

First file creation

  • We can use a text editor or vim for the editing of the file.

first file in vim

  • Now, after we enter the information in the file, lets stage it.
  • When a particular file is staged, Git makes the file ready for committing into the Git timeline.

git add

Git add

  • Now, lets check the status of the git repository Git status

git commit

  • After the file is staged, we need to commit the file into the Git timeline
  • Committing is like taking a snapshot of the staged files with all the changes made.
  • The command is as follows

git commit

  • When the above command is used, vim editor is openedImage description .     I -> insert mode     :wq -> exit vim

Commit in vim

  • We can also use the git commit -m "commit message" to skip using vim.
  • So let's consider a case where you pushed a commit which is bad for the pipeline. In this case, we need to revert the commit.

git log

  • Let us use the git log command to list all the previous commits inside the repo.

git log

git log realtime

  • In the above screenshot, one can see all the metadata about the commit, like the name and username. This data was entered through the git config --global command.

git revert screen

  • Following is the screen when we reverted to the original commit.

git revert vim

  • Its amazing how version control works right?

  • Now, lets connect this offline repository to a online one.

  • For demonstration, here I'll be using GitHub.

Configuring Remote Repository

  1. Let's first Visit GitHub.

  2. Now, let's Sign in. I have an account, Also take a look at GitHub Student Developer Pack.

  3. After signing in, on the leftmost part of the screen, let's click on the New button.
    GitHub first image

  4. Now, let's choose a repo name which is catchy and relevant
    New Repo.

  5. Now, head over to the end of the page, and click on "Create Repository".

  6. After the creation of the repository, we can add files through browser upload or we can use Git for pushing the files.
    Git repo created

  7. Lets use git here.

Using Git to upload files to origin

  • Let's head over to the terminal, and type the following command git remote add origin

git remote add origin

  • Now to see the linked remote repo's to your local repo, we can use the command

git remote list carbon

git remote list terminal

  • Now since everything like commits are wrapped up at our local repository, we hence put forth the legendary command!


  • Note : Here if you can use your own Personal Token to access Git, or sign in if that option exists

  • Note : The default branch name vary from user to user, some use master, some may use main, some may use default. You could refer this article.

  • After the command is used, this is how our GitHub Repo looks like.

GitHub repo page

  • There are Git Branches again, which I will discuss in an another article.

Top comments (0)