Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Updated
10 min read
Git for Beginners: Basics and Essential Commands
S
Professional coder. Occasional bug creator 😎

So you've heard the word "Git" thrown around a lot lately and you have no idea what it means. Maybe your senior dev said "just push it to Git" and you nodded like you totally knew what that meant. We've all been there. Don't worry. By the end of this article you're going to actually understand what Git is and why literally every developer on the planet uses it.

Let's get into it.


What Even Is Git?

Okay so imagine you're writing a really important essay. You save it as essay_final.docx. Then you make some changes and save it as essay_final_v2.docx. Then again as essay_final_ACTUALLY_FINAL.docx. And somehow you end up with essay_final_USE_THIS_ONE_bro.docx.

Sound familiar? Yeah. Now imagine doing that with thousands of lines of code across a team of 10 developers. That's a nightmare.

Git fixes all of that.

Git is a distributed version control system. I know that sounds like a mouthful so let me break it down:

  • Version control means Git keeps track of every change you make to your files over time. Like a really detailed history book for your code.

  • Distributed means every developer has a full copy of the entire project history on their own machine. Not just the latest version but the whole timeline. So even if the main server crashes everyone still has the full history. That's honestly pretty cool.

Git was created by Linus Torvalds in 2005. Yes the same guy who created Linux. He built Git in just a few weeks because he was frustrated with the existing tools at the time. Absolute legend.


Why Do Developers Use Git?

Let me paint a quick picture. You're building an app and everything is working perfectly. You decide to add a new feature and suddenly everything breaks. Without Git you'd be sitting there crying wondering what you changed.

With Git? You just go back to the last working version. Done. Crisis averted.

Here's a quick list of reasons why Git is a must:

1. It saves your entire history Every time you save progress with Git it remembers exactly what changed, when it changed and who changed it. It's like having unlimited undo but way more powerful.

2. Teamwork becomes easy Multiple developers can work on the same project at the same time without accidentally overwriting each other's work. Git handles merging all that code together.

3. You can experiment safely Want to try a risky new feature? Git lets you create a separate "branch" to experiment in. If it goes wrong just delete the branch. Your main code is untouched.

4. It's free and open source Git costs nothing. It's available on Windows, Mac and Linux. And it's been battle tested by millions of developers worldwide.

Fun fact: Git is not the same as GitHub. Git is the tool. GitHub is a website where you can store your Git projects online and collaborate with others.


Git Basics and Core Terminologies

Before you start running commands it really helps to understand the vocabulary. These are the words you'll hear constantly so let's make sure they actually make sense.

Repository (Repo)

A repository is basically your project folder but with superpowers. It's where Git stores your files and the entire history of changes. When someone says "clone the repo" they just mean download the project along with all its history.

There are two types:

  • Local repository - lives on your own computer

  • Remote repository - lives on a server like GitHub or GitLab

Commit

A commit is like a checkpoint or a save point in a video game. Every time you commit you're telling Git "hey save my progress right here with a little note about what I did." Each commit gets a unique ID so you can always go back to it.

A good commit message sounds like: "Add login button to homepage" not "stuff" or "asdfgh". Please write real messages. Your future self will thank you.

Branch

Think of your project as a tree. The main trunk is your primary code and branches are separate paths where you can work on new features or fixes without touching the trunk.

By default Git gives you a branch called main (older projects might call it master). You can create as many branches as you want. Once your feature is ready you merge it back into main.

Staging Area

This one trips up a lot of beginners. Think of the staging area as a shopping cart. You're going through your files and picking which changes you want to include in your next commit. Once you're happy with what's in the cart you checkout (commit) and save that snapshot.

So the flow goes like this:

You make changes in your working directory. You hand-pick what to save using git add to put things in the staging area. Then you commit to lock it into the repository forever.

HEAD is just a pointer that tells Git "this is where you currently are in the timeline." It usually points to the latest commit on your current branch. When you switch branches HEAD moves with you.


Common Git Commands (With Real Examples)

Alright now let's actually do stuff. Here are the essential commands you need to know as a beginner.

Setting Up Git for the First Time

Before anything else you need to tell Git who you are. Run these once after installing Git:

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

This just attaches your name and email to every commit you make. Think of it as signing your work.


git init

This command turns a regular folder into a Git repository.

mkdir my-project
cd my-project
git init

After running this you'll see something like Initialized empty Git repository in .git/. That hidden .git folder is where Git stores everything. Don't mess with it manually.


git status

This is probably the command you'll run the most. It shows you what's going on in your working directory. Which files changed? What's staged? What's not tracked?

git status

Sample output:

On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    index.html

It's like asking Git "hey what's the current situation?" Run this constantly. Seriously. It's your best friend.


git add

This is how you move files to the staging area (your shopping cart from earlier).

# Add a specific file
git add index.html

# Add all changed files at once
git add .

The dot . means "add everything that changed." It's super handy but be careful you don't accidentally add files you didn't mean to include.


git commit

Once your staging area is ready you commit to save that snapshot permanently.

git commit -m "Add homepage layout"

The -m flag lets you write your commit message right there in the command. Always write a meaningful message. A good rule of thumb: write it like you're completing the sentence "This commit will..." so "Add homepage layout" or "Fix broken navigation link."

Pro tip: You can combine add and commit for already-tracked files like this:

git commit -am "Fix typo in header"

But this won't work for brand new files that Git hasn't seen before. For those you still need git add first.


git log

Want to see the full history of commits? This is your command.

git log

It'll show you something like:

commit a3f5c2e (HEAD -> main)
Author: Your Name <you@example.com>
Date:   Thu Mar 26 10:00:00 2026

    Add homepage layout

commit b1d9823
Author: Your Name <you@example.com>
Date:   Wed Mar 25 09:30:00 2026

    Initial commit

For a cleaner one-line version use:

git log --oneline

Output:

a3f5c2e Add homepage layout
b1d9823 Initial commit

Much cleaner right?


git branch

To see all branches in your project:

git branch

To create a new branch:

git branch feature-login

To switch to that branch:

git checkout feature-login

# Or the newer way (Git 2.23+)
git switch feature-login

git merge

Once you're done working on a feature branch and you want to bring those changes back to main:

git checkout main
git merge feature-login

Git will combine the code from both branches. If there are no conflicts it's smooth and automatic. If two people edited the same line Git will ask you to manually decide which version to keep. Those are called merge conflicts and they're a normal part of working in teams.


git clone

If a project already exists on GitHub and you want to download it:

git clone https://github.com/username/repository.git

This downloads the whole project with the entire Git history included. Way better than just downloading a zip file.


git pull and git push

Once you connect your local repo to a remote (like GitHub):

# Download and merge the latest changes from remote
git pull origin main

# Upload your local commits to the remote
git push origin main

pull = bring stuff in. push = send stuff out. Easy to remember.


A Simple Developer Workflow From Scratch

Let's put it all together. Here's what a typical session looks like:

# 1. Start a new project
mkdir my-app
cd my-app
git init

# 2. Create a file
echo "Hello World" > index.html

# 3. Check the status
git status

# 4. Stage the file
git add index.html

# 5. Commit it
git commit -m "Initial commit"

# 6. Create a new branch for a feature
git switch -c feature-dark-mode

# 7. Make changes to index.html and then save progress
git add .
git commit -m "Add dark mode styles"

# 8. Go back to main and merge your feature
git switch main
git merge feature-dark-mode

# 9. See your commit history
git log --oneline

And just like that you've got a real Git workflow going. That's genuinely what developers do every single day.


Small note and a helpful cheat sheet

Git feels confusing at first but honestly it clicks pretty fast once you start using it on a real project. The key is to just start. Create a folder, run git init and start committing stuff. You don't need to understand everything at once.

Here's a quick cheat sheet to bookmark:

Command What It Does
git init Create a new repo
git status Check what's going on
git add . Stage all changes
git commit -m "msg" Save a snapshot
git log --oneline See commit history
git branch name Create a branch
git switch name Switch branches
git merge name Merge branches
git clone url Download a remote repo
git pull Get latest changes
git push Upload your changes

The more you use these the more natural they'll feel. Every great developer out there started exactly where you are right now.

Go build something cool and commit often!