Git Basic Commands

Namrutha Hari
4 min readAug 26, 2021

--

New to Git? Do you feel Git is not your cup of tea? Here are the only commands you actually need to know, for your first commit!

Well, I understand your sentiments because when I first wanted to learn, how to use Git, I got overwhelmed with the long list of commands. To be honest, even now I don’t remember many commands in Git because when it comes to the actual usage there are only a few commands which you will be needing on a frequent basis.

Git is the perfect way to store your precious coded files in a easy and organized way! So you should definitely learn it.

What if I made the entire process of learning Git commands a bit easier for you? I will be mentioning the Git commands I use the most!

Introduction

Git is a Version Control System which helps store different versions of your code. It was created by Linus Torvalds in 2005.

Today, in the coding world, Git is a pretty popular term and is a savior software for coders since it tracks every change made to the code. This golden feature not only helps save time but also helps to collaborate with other people online, in an organized way.

Difference between Git and GitHub

▪ Git is the software present in your local machine which helps send your initial code files into the remote server (i.e. the Internet).
▪ GitHub is the Git repository hosting service. In simple terms, the place or website where your code files can be seen by collaborators online.

Getting started / Installation

There are three main things to do for getting started and you will be ready to start!

  1. Install Git here.
  2. Sign Up for your GitHub account here.
  3. Avail free GitHub Pro Account here for tons of free benefits!

Basic Terms

There are some basic terms, that you need to know so that you understand this blog better!

Repository/Repo — Contains files, history and configurations managed by Git.

Local System/Repo — File storage area in your system

Remote System/Repo — File storage area in online (i.e. GitHub)

Working directory — Files/directory you have been working on.

Staging Area — Pre-commit holding area (i.e. the stage after adding files using git)

Basic Commands

As I promised, let’s learn the most simple Git commands!

git config => configures user info across all local repogit init => transforms current directory into a git repogit status => shows current state of your working git repogit remote => lists the remote repo your local repo is connected togit add => adds file as it looks now in stage until your next commitgit rm => removes file from stagegit commit => commits your staged contentgit push => sends file/changes from local to remote repogit pull => brings files/changes from remote to local repogit clone => copies all the files from an online repo to your device

How to use these commands?

Did you get a heart-attack after reading the long list? Don’t worry, we will be needing only a few for making your first commit!

To understand the workflow of the steps we will be doing here, refer this diagram!

Git Workflow Diagram

Steps to follow:

  1. Open your Command Prompt (aka cmd/cli )in your PC.
  2. Type file path using ‘cd’ (aka change directory) command.
cd C:\Code\HelloWorld.txt

3. For first time git users use ‘git config’ and type your name and email to connect your local machine to GitHub account.

git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"

4. In cmd, let’s tell Git that this is the file we want to be sent to GitHub. So we type ‘git init’ command.

git init

5. Open GitHub and make a new repository.

Steps to create new repository in GitHub

6. Assign default branch using ‘git branch’ command.

git branch -M main

7. Connect new GitHub/remote repository to your local repository, using ‘git remote add origin [https link]’ command. Copy your unique https link from your new GitHub repository and paste it.

For example,
‘https link’ —
https://github.com/namruthahari/basic-git-commands.git

git remote add origin [https link]

8. Add all current files in directory, using ‘git add .

git add .

9. Commit the added files to staging area, using command ‘git commit -m ’.

git commit -m “first commit”

10. Finally, push all your code online, using ‘git push’.

git push -u origin main

Your files now would have been successfully pushed online. Reload your repository in GitHub to see the files.

Note:
These steps are to be followed for every new repository you make !
Once all these steps are carried out, only commands like ‘git add’, ‘git commit -m’ and ‘git push’ need to be used to push new changes in your files!

Ending Note

I hope this blog, helped you understand Git!
If you run into any sort of difficulty, let me know. You can reach out anytime! Do comment if you need a YouTube video, to understand this better.

See you all next time!

Cheers,
Namrutha Hari

LinkedIn

YouTube Channel

Instagram

https://www.instagram.com/clickfornamz/?hl=e

Medium Blog Profile

Twitter

--

--

Namrutha Hari

UG Fresher pursuing BTec @ SRM University. Sharing experiences through writing and videos. Blogs related to technical and various programs.