Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Updated
3 min read

Topics to cover

  1. What is Git

  2. Why Git is Used

  3. Git Basics and Core Terminologies

  4. Common Git Command

What is Git

Git is a powerful version control system tool used by developers when they work on a project. It is a distributed and open-source tool that helps developers collaborate with each other and keep track of their code while writing it.


Why Git is Used

Git helps developers in many ways when they work on the same project. It allows them to collaborate with each other easily. Git keeps a record of all changes, such as the date, time, the person who made the change, and the code that was updated. It also helps developers recover the previous or older versions of their code if something goes wrong.

Git Basics and Core Terminologies

Repository (Repo)

A project folder that Git tracks. It contains all your files and their complete history.

Commit

A saved snapshot of your changes with a message describing what you did. Like a checkpoint in a game.

Branch

A separate line of development. The main branch is usually called main or master. You can create branches for new features without affecting the main code.

HEAD

A pointer to the current branch or commit you're working on.

Working Directory

Your actual project files on your computer.

Staging Area

A "waiting room" where you prepare changes before saving them permanently with a commit.

Git Workflow Visualization

1. Basic Workflow

2. Local Repository Structure


Essential Git Commands

# Initialize a new Git repository in your current folder
git init

# Clone (download) an existing repository
git clone https://github.com/username/repository.git

Checking Status

# See which files are changed, staged, or untracked
git status

# Show the commit history
git log

# Show compact history
git log --oneline

Viewing Changes

# Show unstaged changes
git diff

# Show staged changes
git diff --staged

# Show changes in a specific commit
git show abc123d

Quick Reference Cheat Sheet

CommandWhat it does
git initStart tracking current folder
git clone [url]Download a repository
git statusCheck what's changed
git add [file]Stage changes for commit
git commit -m "[msg]"Save changes with message
git logView commit history
git branchList/show branches
git checkout [branch]Switch branches
git merge [branch]Combine branches
git pullDownload updates
git pushUpload your changes

Common used diagram

Summary

If you want to make your life easier as a developer, you should use Git. Git helps you work in an organized way and collaborate smoothly with your team. It keeps your code safe, tracks changes, and makes teamwork simple and efficient.🎶