Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
3 min read

1. What is GIT

Git is a open source project developed in 2005 by Linus Torvalds, famous creator of the Linux operating system kernel. It is a version control system where we keep track on changes we are making in our codes.

Git is an example of a DVCS (hence Distributed Version Control System). Rather than have only one single place for the full version history of the software as is common in once-popular version control systems like CVS or Subversion (also known as SVN), in Git, every developer's working copy of the code is also a repository that can contain the full history of all changes.

2. Why Git is Used

a. Track Changes - To track changes in the code every time when someone committing.

b. We can make clone of the project we are working on, so that if something happens to the original code, we will have a copy of it which is not possible in centralized system.

c. We can work on the project from anywhere, it doesn't require internet connection like centralized system.

d. We can easily collaborate with each other over git without disturbing their code.

e. Experiment Safely: Create branches to test ideas without breaking main code. f. Debug Fast: (git log + git bisect) finds exactly when bugs were introduced.

3. Git Basics and Core Terminologies

Git thinks of your project in three main areas: working directory (your files), staging area (prep zone for changes), and repository (permanent save vault).

Working Directory ← Staging Area ← Repository (.git)
     (files)         (git add)       (git commit)
git status     # See what changed (before coffee spill deletes files)
git add .      # Stage your 🐛 bug fixes  
git commit -m "🐛 Fix login"  # Saved forever
git push       # Share with team

Git stores everything in your local .git folder—a full database of commits, branches, and file history.

  1. Repository

    The folder holding your project + all history. Local (on your machine) or remote (like GitHub).

  2. Commit

    Snapshot of all files at one moment + metadata.

  3. Head

    Pointer to where you are (file: .git/HEAD).

  4. Branch

    Pointer to a commit (lightweight file in .git/refs/heads).

  5. Git flow:
    Working Directory (editable files) → Staging Area (git add) → Repository (git commit). Arrows show the progression with example files.

git status     # Where's HEAD?
git add .      # Prepare snapshot
git commit     # New object in .git → HEAD moves
git log        # Walk backward from HEAD

4. Essential Git Commands

a. git init

Initializes a new Git repository in the current directory.

b. git clone

Creates a copy of an existing remote repository.

git clone <repository-url>

c. git status

Displays the state of the working directory and the staging area. It shows which changes have been staged, which haven't, and which files are not being tracked by Git.

d. git log

Shows the commit history for the current branch.

e. git add

Adds changes from the working directory to the staging area.

f. git branch

Lists all branches in the repository. The * indicates the current branch.

That’s all about GIT