Skip to main content

Command Palette

Search for a command to run...

Beginner's Guide To Git

Published
•3 min read•View as Markdown
N

Neha Chopra | Finance Writer → Full-Stack Developer in Progress I write finance case studies and analytical articles, and I’m currently transitioning into web development. Passionate about building clean, functional web experiences while bringing an analytical mindset from finance into tech.

1. What is Git?

Git is a Version control system.

In simple words, it helps us track changes in our code files over time.

When we work on a project, git keeps track of

  1. What changed?

  2. Who made the changes?

  3. When was the change made?

We can also go back to older versions if something breaks!!

Just like photo albums that behold our memories and not overwrite new ones, git saves various versions instead of overwriting! Git is like working on a draft copy instead of the final notebook—we experiment freely.


2. Why is Git used?

Git is used because it makes working on projects safe, organized, and collaborative.

Main reasons to use Git:

  1. Track changes

    • We can see what was changed and why.

    • Useful when debugging mistakes.

  2. Working without fear

    • If something goes wrong, we can go back to a previous working version.
  3. Team collaboration

    • Multiple people can work on the same project without overwriting each other’s work.
  4. Branching

    • We can try new features without disturbing the main project.

    • If it works, We merge it. If not, we discard it.


3. Git Basics and Core Terminologies

Repository (Repo)

A repository is a project folder tracked by Git.

It contains files and Git’s history.

Analogy:

It is like a project file cabinet that stores all files and their history.

Working Directory

This is the folder where we edit our files normally.

Staging Area

A place where we select which changes should be saved next.

Commit

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

Branch

A branch is a separate line of development.

  • Main (or master) is the default branch.

  • Feature work is usually done on other branches.

Merge

Merge means combining changes from one branch into another.

Remote

A remote is a Git repository stored online, like on GitHub or GitLab.


4. Common Git Commands

Below are some commonly used Git commands with simple explanations.

git init

Creates a new Git repository in a folder.

git status

Shows the current state of files (changed, staged, untracked).

git add

Moves changes to the staging area.

git add file.txt
git add .

git add .

Moves changes in all files in CURRENT FOLDER to staging area.

git commit

Saves the staged changes with a message.

git commit -m "Added login feature"

git log

Shows the history of commits.

git log
git log --oneline

git revert

This helps us to revert back to the desired previous version.

git revert <hash>

git reset

This function helps us reset the head.

git reset <hash>
git reset --hard <hash>

git branch

Lists all branches.

git branch

git checkout

Switches between branches.

git checkout feature-branch

git merge

Combines one branch into another.

gitmerge feature-branch

git clone

Copies an existing remote repository to our system.

gitclone <repository-url>

git pull

Gets the latest changes from the remote repository.

git pull

git push

Uploads our local commits to the remote repository.

gitpush

Conclusion

Git is a powerful tool that helps developers track changes, collaborate easily, and work confidently.