Git for Beginners: Basics and Essential Commands
đď¸Introduction
Weâre back with another blog â with our recent star of tech world: Git â.
Let me start with my own story a bit, while starting out my coding journey. I initially leaned toward Game-Dev. And I used to watch tutorials of the C language, learn its concepts and apply on projects.
At some point I even copy pasted the code shown in YouTube videos, comma-to-comma. But still ended with some bugs and errors. I didnât know about Git back then.
I saved code locally, created multiple folders, and copied the same code again and again just to avoid breaking the working version.
The fog cleared up, I stopped copy-pasting tutorial code, worked on basics, understood Game-Dev isnât for me, and learned about Git.
So I am here to speak my thoughts about Git. Let me explain more:
đ What is Git?
Basic Idea: Git is a system that tracks changes in code over time.
â Things Git performs:
- A time machine for our code
- A memory management for project
- A safety net that lets us experiment without fear.
(Simple Example: A strict mom but for code. )
â Git vs GitHub:
â Git is a tool, lives on your machine, works offline
â GitHub is a platform, that provides collaboration, social connection with developers, works online
When a group of developers, in old times use to contribute to the same codebase, they used pendrive analogy, FTP and many other stuff.
(Hey, You donât know Pendrive Analogy, are you the same guy from my previous blog đ¤. If not, go checkout my previous blog:
Blog 1: Why version Control Exists: The Pendrive Problem )
Think of it like Google Docs history, but for entire project â files, folders, everything.
Git doesnât just save files.
It takes snapshots of changes over time.
- You mess up? â Go back.
- Something worked yesterday? â Prove it.
- Want to experiment? â Do it safely.
Imagine it like a rewind button, a log book, and a sandbox â all in one into our coding workflow.
đ Why is Git is Used?
As humans we make mistakes
Letâs admit, Developers are not perfect. Everyone working on same project tends to make a mistake intentionally or unintentionally.
-> Without Git:
- Developers may break the code
- Forget what they changed (unless, they are writing all changes in a notebook)
- Work with other humans (collaborative humans)
- Say âIt worked yesterdayâ way too often
-> With Git:
- Everyone has their own of project (called a repository)
- Mistakes are not permanent and can be undone without losing progress.
- Changes are tracked and merged intelligently
- Experimentation is allowed, which provides new way of working
( Personally, I believe we living in the post Git era is a bliss. Thank you Linus Torvalds, for making our code management easy)
Git gives developers an unseen confidence â a backbone of modern software development.
đ§Š Git Basics and Commands
(This is the main ingredient of this Blog, I assume that is why you are here)
Letâs breakdown the key concepts of Git in beginner-friendly terms:
-
Repository (Repo)
- Most used Git term, among developers
- Home-ground for all the code files, folders, resources
- This is where Git stores all the files and their history
- It contains
.gitfolder = Gitâs brain
-
Working Directory:
- This is the active repo, where you actively saving/pushing code files & folders.
- This directory contains the files you actively edit before Git tracks them.
-
Staging Area:
- Before actually pushing the code, we get to see what files or folders will get pushed.
- Think of it like a snapshot before actually changes in GitHub repo.
-
Commit:
- A snapshot of your project at specific moment.
- Think of it like âsaving pointâ in a game, to respawn later and continue
- Comes with a message (future-you-says thanks)
(Believe when I say to type a message before any commit, because later youâll forget what you changed. Make you commit messages meaningful)
-
Branch:
- A parallel timeline for your code.
- You can experiment your coder instinct here without disturbing the main timeline.
(Imagine it like a clone of yourself, respawned in alternate universe same as yours. Now you can do things with that clone too.)
-
Head:
- Your current position in the codebase. (Gitâs way of saying âthis is where you are right nowâ)
- Simple way: A pointer to current commit.
(If you donât understand, itâs fine. Git sorts this task for you)
đ ď¸ Common Git Commands
Letâs walkthrough a simple workflow as if youâre starting fresh:
(Before anything, Open a folder in VS Code, navigate to cmd terminal and perform these commands)
You can create files using your IDE or terminal â both work.
â Git WorkFlow:
-
Create a Folder
mkdir your-project-name cd your-project-name
-
mkdir: stands for make directory -
cd: stands for change directory - Above command changes your directory and change to the current one. ( In our case, new project created)
-
init: stands for initialization. - Above commands means, we want to initialize a
.gitfolder in the current project directory. - Simply, set up s hidden
.gitdirectory to manage and store the changes
-
echo: a command which is used to print the text to output tab -
>: this simple greater than sign means to shift the contentâHello Gitâto the hello.txt file - Above command means to write âHello Gitâ to a file called hello.txt in the directory. (If a file hello.txt is not present, it creates one for us)
-
You can change the file name, or the content under â â according to your needs.
echo "Another Line" >> hello.txt >>: two greater than means we don't want to overwrite previous content instead, we want to add another line.Above command means to write another text line
(Another line)in the hello.txt file.
- Above command means to show us which files are new, modified, staged
- At this point, hello.txt will appear an untracked file
- Above command moves file into staging area, preparing to commit.
-
You can stage multiple files or use
git add .to stage everything.Git Ignore
Hey readers!! If you are so far here I would like to add more to your journey.
Sometimes youâll have files in your project that you donât want the Git to track â like temporary files, logs or sensitive config files. To handle this, we use a special file called
.gitignoreLetâs back to the topic now.
-
commit: saves changes to your local repository. -
-m: stands for messages - Above command means, save staged changes in repository hstory with the message you gave (In our case,
"First Commit: Add hello.txt")
Summary:
- Folder creating â
mkdir/ Editor - Initialize repository â
git init - Add Files â
echo/ Editor - Check status â
git status - Stage Changes â
git add - Commit â
git commit -m âyour-messageâ
Other Powerful Commands:
These commands comes in handy, being a developer I have used a lot. If you are dev too, you know them too.
- Shows up your code history with an ID, author, author-email, date and message.
- Reading commits like timeline (I would say flipping through a coding diary)
-
diff: stands for difference Shows changes you've made in files but haven't added it. You'll see the line differences.
--(minus) â content removed
-+(plus) â content added-
Works before
git add. If you run it after staging, it returns nothing because changes are already in staging area.git diff commit1 commit2 You can also use the ID of your selected commits, to see the difference between them.
-
creates a new branch with name you have given
Branch List
git branch -
shows all the git branch list, connected to your current repository.
Change Branch
git checkout branch-name shifts the branch from the current one, to the mentioned one
By the end, youâve not only built your projectâyouâve built a history of your project.
đ Common Beginners Mistake:
Learning about isnât about perfection â itâs about making mistakes and realizing theyâre part of the journey.
Basic Mistakes every beginner bumps into:
â Forgetting to commit:
Every changes needs to be mentioned and stored in history. One last avoidance of procastination may lead you a good commit timeline.
â Committing everything blindly:
Running git add . and committing without checking whatâs inside leads you to a loop of debug logs and secret configs in repo.
(Even we check the person, before committing to marry him/her. Why not your CODE!!)
â Writing bad commit messages:
Fix stuffâ or âUpdate codeâ doesnât help future you (or teammates). A good commit message is like a diary entryâit tells the story of what changed.
â Being afraid of Git errors:
Seeing âdetached HEADâ or âmerge conflictâ feels terrifying at first. But Git errors arenât disastersâtheyâre just puzzles waiting to be solved.
Everyone breaks Git once.
The pros just know how to fix it.
At last,
This is the end.
Hold your commits and count to ten
Feel the Git moving, and then
Remember your commit message again
~ Hayat (Original)
Now, you have covered so much of the Git basics â now itâs time for you to get moving and put your laptop to work.
- Practice locally â Start small, experiment freely, and let Git become second nature.
- Break things on purpose â Mess up boldlyâfixing mistakes is the fastest way to learn.
- Learn branches next â Branches are your playground for safe experiments.
- Explore GitHub after mastering basics â Share your work online and step into real collaboration.
Weâll meet again in the next blog, where we go under the hood of .git.












Top comments (0)