Git and GitHub Basics: Part 1 — git commands

Source: unDraw.co

What is git?

What is GitHub?

In this blog we will create a software project, use git to track changes and in the next one we will host our project in the cloud using GitHub.

I have created a folder named KickStartGit that has two files index.html and README.md.

The index.html contains the source code of our project and README.md contains information on what our software project is about.

Creating files inside the KickStartGit folder

Setting up git bash

Once git bash is installed, head over to the working directory (in my case it is the KickStartGit) and right click anywhere on the screen, and select the option Git Bash Here

Bringing up git bash here option

A window such as this should appear

git bash window

After this we add our GitHub username and email id. Use the command git config --global user.name "Your name" to configure your username and git config --global user.email "Your email" to configure your email.

If your configuration was successful, you’ll have your username and email address returned once you type in these commands and hit enter.

git config --global user.namegit config --global user.email

You should get something like this

Basic git commands

Commonly used git commands

git init

git init
Executing the git init command

A brief side note; before moving on to other git commands, we need to understand about a git terminology called a staging area or index

Staging area

A staging area can be thought of as a preview of all the files that are changed before the changes are saved with a message. This process of saving changes with a message is called commit-ing. The files can be added and removed from the staging area. Git has three areas where files changes can be stored.

Three places where changes to the files can be stored

git status

git status

This command is only used to display information and does not modify any information in the working directory. Main categories of git status call are:

  • When a new file is added/deleted
  • When an existing file is modified
git status example

git add

git add [filename]

The above commands add a single file to the staging area

If you wish to add all the files that are changed to the staging area, then use the following command

git add .

The ‘.’ adds all the files in the current directory that have changed

TL;DR

  • Initialize git, i.e. git init to track changes of your working directory
  • Use git status command to check the state of the files in your working directory
  • Use git add to add the changes to the staging area

In the next post, we will “push” our code to a GitHub repo and talk about more useful git commands. Stay tuned!

--

--

Tech enthusiast and computer programmer

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