Understanding the Git and Github (Everything you need to know to get started)

Version Control System
Dev
Data Science
Git
Code
Author

Mukesh

Published

June 11, 2025

Version Control System

Version Control System simply means we can go the back to version we want to. There are Various version Control system available such as git, CVS, Subversion, Perforce, Bazaar, and so on.

flowchart LR
Z[v0]-->A[v1]-->B(v2)-->C(v3)
master[Your here] -->C

We are at the version 3 we can go back to we version 2 and made the changes come back. It will be very usefull when we collaborating with many people.

flowchart LR
Z[v0]-->A[v1]-->B(v2)-->C(v3)
master[Your here] -->B

Git and Github

We are going to see Git and github(largest host for git repository)

Three states of git

  1. Modified (Files you are Modified)
  2. staged (Modified file are taked out to store in local database)
  3. commit (Staged files are stored in local database)

Installation

  • Install the git based on your operating system.
  • Create a github account.

It is Straight forward, if you are having problem in installing feel free to ask.

Initial Config

$ git config --global user.name "Your Name"
$ git config --global user.email yourname@example.com

You can also config your editor, if you just starting out start with notepad for better understanding of concepts.

Git Basics

If your are beginner feel free to follow along with me. Once your comfortable you can create your own repository and test it out what you are learned. repository(repo) - Nothing but a folder

Basic Commands

  • ls -> list the file or folder in that region
  • ls -a ->(list the hidden files) it work on the linux
  • mkdir -> create a new folder
  • cd -> change the directory or get in to the directory
  • rm -> , rm -r recursively remove everything

Git Initialization, stage, commit

Git Initialization

  • mkdir understand_git -> Create a folder with name understand_git
  • cd understand_git -> get into the understand_git folder
  • git init -> initialize the git in the folder
    • ls -a -> if you want to look out what what it initialized is .git(It work on linux)

Git stage

  • Create a README.md file in the repo. And write a sentence like this is about understanding git.
  • git status -> Check the status of file. It shows on master branch and README.md file as untracked file.
  • git add . or git add * (If you want to particular file -> git add README.md)

Git Commit

  • Check the status(git status) untracked file become become tracked(File colour changed from red to green)
  • git commit -m “Inital commit” (-m is the message for our local storage in case we want to go back it will be very usefull)
  • git status -> Branch is clean nothing to commit
    • git status -s (Short status for the track)

Ignoring files/folder

There are few file/folder like cache, log, etc. We don’t need to maintain history or track for that type of file and we can ignore from tracking by creating .gitignore file and add the name of the file or folder to ignore. We can also use Regular expression to ignore file

Staged and Unstaged changes

  • let’s open a README.md file and add the second line like git is a powerfull tool
  • git status will show the file is modified
  • git diff -> Shows the what is modified from the last commit
  • git diff –staged or git diff –cached -> What are change in the staged file difference from the previous commit

Skipping the staging area.

If you also skip the staging area and directly stage and commit

  • Add a line in README.md like github is amazing.
  • git commit -am “Let’s skip the stagging area” or git commit -a -m “Let’s skip the stagging area”.
  • Use it carefully sometime we don’t want to add every changes in every file.

Unstage the staged file

If you are accidently staged some file and want to unstage the file

  • create a text file called file_1.txt and add a line like nature is amazing
  • git add . -> it adds the file to the staging area and you accidently added that file for staging
  • git rm –cached file_1.txt -> it will unstage the file_1.txt
  • you can also do it by (git reset file_1.txt)

Log

  • git log -> Gives the commit history(It is very much usefull when we want to roll back)
  • git log –stat -> Gives the commit history with changes

Undoing the commit message

  • If you mess up with your commit message you can go back and edit the message.
  • Open README.md add text in a new line like i love programming
  • git add .
  • git commit -m “added”
  • you just added the message as added so i want message as added a new line
  • git commit –amend -> It will open message prompt to re-enter your commit message.

Unmodifying a modified file

  • Open README.md add text in a new line like Python is great
  • Check the git status, README.md is modified
  • git checkout – README.md -> it will roll back the modified file.

Git restore

  • git restore –staged file_name -> Unstage the staged file
  • git restore file_name -> Unmodifying the modified file

What to use?

  • git reset or git cached or git restore - I will suggest git restore because it is powerfull than others

Git Branching and Github

Github Intro

  • Github largest host of git repo- Hope you already created that account if your are following this.
  • For practice purpose i will create a understanding_git repo in my github you can fork it follow along and i will merge your pull request.
  • Github uses main instead of master branch from few year back you can also configure from name as main/master

Git branching

Before deep diving in to the branches let understand few basics. - You are not able to directly commit on the project of the team/Organization. - First you need a copy of the project in your repo just click the fork of this project at the right side here. - Once it forked copy the url from the code dropdown or repo url. - git clone url -> This command will copy the repo in the local.

Create a new branch Once cloned
  • Never ever commit on the master/main branch
  • New branch new issue

Contribution to a project

  1. I test the every command so anything not working create an issue here
  2. git remote upstream https://github.com/MUKESHRAJMAHENDRAN/understanding_git (This will add origin of the forked repo)
  3. git branch inspired_line -> Create a new branch
  4. git checkout inspired_line
  5. add your line on the quote.txt
  6. git add .
  7. git commit -m “Added the line”
  8. git checkout main
  9. git pull upstream main -> If any change are commited on the parent main branch that with sync with main branch of the local
  10. git merge inspired_line (It open message prompt and type what merge message is all about)
  11. git push origin main
  12. Once pushed go to your repo of understanding_git from the contribution create a open pull request i will merge it
  13. Once merged delete the branch name
  14. git branch -d inspired_line

This blog is just a fuel to kick to get starting there are so much things to learn from git and github like Git Rebase, merge conflict, cherry pick, git on the server, distribution of git, branch Workflow, etc.We will learn in the upcomming post.