Learn Git Easily: A Beginner's Guide to Version Control
Source: Dev.to
Git
In technical terms: Git is a Distributed Version Control System (DVCS).
In simple terms: Git is a time‑machine for your projects. It tracks every modification you make to your code, so if you break something you can simply “rewind” to a previous, working state.
Why do we use it?
- Collaboration – Multiple people can work on the same files simultaneously without overwriting each other’s work.
- Distributed architecture – Every developer has a full local copy of the repository (history and commits). This enables offline work and eliminates a single point of failure.
- Branching & merging – Developers create a separate branch for a feature and later merge it back into the main branch.
Terminology Dictionary
| Term | What it means |
|---|---|
| Repository (Repo) | The folder containing all project files and the entire revision history. |
| Commit | A snapshot of your code at a specific point in time; identified by a unique hash. |
| Staging Area | The list of files you are preparing to commit next. |
| Local | The repository stored on your personal computer. |
| Remote | The repository stored on a server (e.g., GitHub, GitLab). |
| Clone | Downloading a remote repository to your computer. |
| Push | Uploading your local commits to the remote server. |
| Pull | Downloading changes from the remote server to your local machine. |
| Merge | Combining code from one branch into another. |
| Branch | A parallel version of your code; changes don’t affect the main project until merged. |
| HEAD | A pointer to the commit you are currently viewing or working on. |
| Origin | The default nickname Git gives to the remote URL you cloned from. |
| Pull Request (PR) | A request to merge your branch into the main branch (used on GitHub/GitLab). |
The Core Architecture
Before moving to commands, understand the three stages:
- Working Directory (The Workbench) – The actual folder where you write code.
- Staging Area (The Box) – You pick specific files from the workbench and place them in the box.
- Local Repository (The Shipping Truck) – You seal the box and label it. This becomes a commit, a permanent part of the project history.

How a Repository Looks

src/– Contains your actual source code, keeping the project organized..gitignore– Lists files/folders Git should intentionally ignore (e.g., secrets).README.md– The instruction manual that explains what the project is and how to run it.LICENSE– Legal document stating how others may use or copy your code..git/– Hidden database where Git stores the entire project history and save points.
The Developer Workflow
Initialize
Tell Git to watch your folder:
git init
Check Status
See the current state of your repository:
git status
Stage
Create a file named index.html. Run git status again – the file appears in red (untracked). Move it to the staging area:
git add index.html
Tip: To stage all changed files at once, use git add .. After staging, git status shows the file in green (ready to be saved).
Commit
Save a snapshot to the history (you must include a message):
git commit -m "Created the homepage file"
-m = “message”.
Lazy Shortcut
Combine staging and committing for already‑tracked files:
git commit -am "Updated the style"
Note: This does not stage new (untracked) files; it only commits modified or deleted tracked files.
History
View a list of all commits:
git log
Difference
Show what has changed between the working directory and the last commit:
git diff
That’s the essential Git workflow. From here you can explore branching, remote collaboration, and many more powerful features Git offers. Happy coding!
Git Cheat Sheet
Diff
When you stage or commit, you should always check what you actually changed.
git diff
Branching
Create a Branch
By default, you are on the main (or master) branch. Create a new branch:
git branch dark-mode-feature
Switch Branches
Switch to the new branch:
git checkout dark-mode-feature
Newer Git versions also support
git switch dark-mode-feature.
Merging
You wrote code in dark-mode-feature, committed it, and tested it. It works! Now merge it back into main.
-
Switch back to
maingit checkout main -
Merge the feature branch
git merge dark-mode-feature
Going Remote
So far everything has happened locally. To share code, you need a remote repository.
Clone
Download an existing repo to your machine:
git clone
Push
Upload local commits to the remote repository:
git push origin main
Pull
Download new changes from the remote to your local computer:
git pull
Stashing
You’re working on a new feature (messy code, half‑broken). Suddenly, a critical bug needs fixing. You can’t switch branches because your work isn’t finished, and you can’t commit it yet. Store your changes temporarily:
git stash
Pop Stash
Retrieve the stashed changes:
git stash pop
Reset
Sometimes you commit too early and want to go back. git reset moves the HEAD to a specified commit. It comes in two main flavors.
Soft Reset
Undoes the commit but keeps your code changes in the staging area.
# Go one commit back (keep changes staged)
git reset --soft HEAD~1
# Go one commit back (keep changes unstaged) – mixed reset
git reset HEAD~1
# Go to a specific commit
git reset
Hard Reset
Undoes the commit and deletes all changes. It reverts everything to exactly how it was before you started working.
# Go one commit back (delete commit + delete changes)
git reset --hard HEAD~1
# Go to a specific commit (delete all changes)
git reset --hard
Warning: This permanently deletes your work. Use with caution.
Revert
If you have already pushed bad code to a shared main branch, you cannot use reset (deleting history that others have downloaded causes conflicts). Instead, create a new commit that undoes the bad one:
git revert
Cherry‑Pick
Your teammate fixed a tiny bug in one commit on a large experimental branch, but you don’t want the rest of their changes. Apply just that single commit to your branch:
git cherry-pick
Rebase
You are working on a feature branch. Meanwhile, the main branch has received new updates, making your branch out of date. Instead of a messy merge, rebase your work onto the latest main to keep a linear history:
git rebase main
Tip
In case of fire: git commit, git push, and let the CI/CD pipeline handle the rest.
— Anonymous Developer