Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
3 min readView as Markdown

1. What is Git?

https://miro.medium.com/v2/resize%3Afit%3A1400/1%2AE1jdYRKin1hraL67-cKALw.png

https://homes.cs.washington.edu/~mernst/advice/version-control-fig3.svg

Git is a version control system.
In simple words, Git helps us track changes in our code over time.

Git is also a distributed version control system, which means:

  • Every developer has a full copy of the project

  • Work can be done offline

  • No single central computer controls everything

So instead of saving files like project_final_v2_last.py, Git keeps proper versions for us.

2. Why Git is Used

https://media.licdn.com/dms/image/v2/C5612AQFfYpEY8j_3LA/article-cover_image-shrink_600_2000/article-cover_image-shrink_600_2000/0/1520244974622?e=2147483647&t=GLQuYQ-pVEmr2ZauVVm3suVkI6XwPM4mA06grdLYUL4&v=beta

https://wac-cdn.atlassian.com/dam/jcr%3Acc0b526e-adb7-4d45-874e-9bcea9898b4a/04%20Hotfix%20branches.svg?cdnVersion=3151

Git is used because it makes development easier and safer.

Some main reasons:

  • We can track changes in our code

  • We can go back to older versions if something breaks

  • Multiple people can work together on the same project

  • Mistakes are not permanent

For college projects, internships, and real jobs, Git is almost mandatory.

3. Git Basics and Core Terminologies

https://git-scm.com/book/en/v2/images/branch-and-history.png

https://www.dasca.org/content/images/main/git-terminology.jpg

Before using Git commands, it’s important to understand some basic terms.

Repository (Repo)

A repository is a folder tracked by Git.
It contains:

  • Project files

  • Git history

Created using:

git init

Commit

A commit is a saved snapshot of the project at a point in time.

Think of it like:

“This is my project state right now, and I want to save it.”


Branch

A branch is a separate line of development.
It allows us to:

  • Experiment safely

  • Work on features without breaking main code


HEAD

HEAD is a pointer to the current commit you are working on.
Usually, it points to the latest commit of the current branch.

4. Common Git Commands

https://www.edureka.co/blog/wp-content/uploads/2016/11/Git-Architechture-Git-Tutorial-Edureka-2.png

https://geo-python.github.io/site/2018/_images/Git_illustration.png

These are the most important Git commands for beginners.


git init

Initializes a Git repository.

git init

git status

Shows:

  • Modified files

  • Staged files

  • Untracked files

git status

git add

Adds files to the staging area.

git add file.txt
git add .

git commit

Saves staged changes as a commit.

git commit -m "Initial commit"

git log

Shows commit history.

git log

5. Basic Developer Workflow Using Git

https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png

https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpxeexqyfvf4hw3zxtbn.png

Here’s how a beginner typically uses Git from scratch:

Step-by-step workflow

  1. Create a project folder

  2. Initialize Git

     git init
    
  3. Write or modify code

  4. Check status

     git status
    
  5. Stage changes

     git add .
    
  6. Commit changes

     git commit -m "Added main logic"
    
  7. View history

     git log
    

Git Flow (Conceptual)

Working Directory
        ↓
   Staging Area
        ↓
     Repository

This flow is the core idea of Git usage.

6. Commit History Flow

https://nvie.com/img/git-model%402x.png

https://user-images.githubusercontent.com/1256329/80170009-f9d03200-85b4-11ea-94d3-3041887565ac.png

Each commit points to the previous one, forming a history.

Commit 1Commit 2Commit 3Commit 4

This makes it easy to:

  • Track progress

  • Debug issues

  • Understand how a project evolved


More from this blog

aks16

15 posts