Git for Beginners
Source: Dev.to
If you are learning programming or working with code, you will hear the word Git everywhere. Git can feel confusing at first, but once you understand the basics, it becomes one of the most powerful tools in your developer toolkit.
This article explains:
- What Git and version control are
- How Git tracks changes
- How to push and pull code
- A simple Git workflow you can follow confidently
You don’t need any prior experience.
1. What Is Version Control?
Version control is a system that helps you track changes made to files over time.
Think of it like this:
- You wrote some code today
- Tomorrow you change it
- Next week, something breaks, and you want the old version back
Version control solves this problem by:
- Keeping a history of every change
- Allowing you to go back to previous versions
- Making it easy for multiple people to work on the same project
2. What Is Git?
Git is a version control system used to track code changes.
Key things Git does:
- Tracks file changes
- Records who made a change and when
- Allows collaboration without overwriting each other’s work
- Works locally on your computer (even without internet)
Git is different from GitHub:
- Git → the tool
- GitHub / GitLab / Bitbucket → online platforms that store Git repositories
3. What Is a Repository?
A repository (repo) is a project folder that Git tracks. It contains:
- Your project files (code, images, docs)
- A hidden
.gitfolder that stores version history
There are two types:
- Local repository → on your computer
- Remote repository → online (e.g., on GitHub)
4. How Git Tracks Changes
Git tracks changes in three main areas:
1. Working Directory
This is where you edit files normally.
index.html
style.css
At this stage, Git sees changes but hasn’t recorded them yet.
2. Staging Area
The staging area is where you prepare changes before saving them permanently.
-
Add a specific file:
git add filename -
Add everything:
git add .
Think of this as saying: “These are the changes I want Git to remember.”
3. Commit History
A commit is a snapshot of your project at a specific time.
git commit -m "Describe what changed"
A commit includes:
- The changes
- Your message
- Date and author
Git Change Flow (Very Important)
Edit files → Stage changes → Commit
5. Installing Git
Check if Git is installed:
git --version
If not installed:
- Windows: Download from git‑scm.com
- macOS: Install via Homebrew (
brew install git) or Xcode command‑line tools (xcode-select --install) - Linux: Use your package manager (e.g.,
sudo apt install git)
6. Creating Your First Git Repository
Navigate to your project folder:
cd my-project
Initialize Git:
git init
Now your folder is a Git repository.
7. Checking File Status
Use this command often:
git status
It tells you:
- Which files are modified
- Which files are staged
- What is ready to commit
8. Making Your First Commit
-
Add files to staging
git add . -
Commit changes
git commit -m "Initial project setup"
You have now saved your first version.
9. Understanding Push and Pull
What Is Push?
Push sends your local commits to a remote repository (like GitHub).
git push origin main
origin→ remote repository namemain→ branch name
Use push when you want to upload your work or let others see your changes.
What Is Pull?
Pull downloads the latest changes from the remote repository to your local machine.
git pull origin main
Use pull when someone else updated the code or you need the latest version before working.
Important Rule: Always pull before you start working to avoid conflicts.
10. Understanding Branches (Beginner Level)
A branch is a separate line of development.
main(ormaster) → stable code- Feature branches → new features or experiments
Create a new branch:
git branch feature-login
Switch to it:
git checkout feature-login
Or create and switch in one step:
git checkout -b feature-login
Branches let you:
- Experiment safely
- Avoid breaking main code
- Work in parallel with others
11. A Simple Daily Git Workflow
A beginner‑friendly workflow you can follow every day:
-
Pull latest changes
git pull origin main -
Make code changes (edit files)
-
Check status
git status -
Stage changes
git add . -
Commit changes
git commit -m "Add login validation" -
Push to remote
git push origin main
12. Viewing History
You can view the commit log with:
git log
Or a more compact, one‑line view:
git log --oneline
Happy coding!
Commit History
See past commits
git log
This helps you:
- Understand project history
- Identify when bugs were introduced
- Revert changes if needed
13. Common Beginner Mistakes
- Forgetting to commit changes
- Writing unclear commit messages
- Not pulling before pushing
- Editing directly on the
mainbranch - Panicking when seeing merge conflicts (they are normal)
14. Why Git Is Essential
Git is used by:
- Solo developers
- Large companies
- Open‑source projects
It helps you:
- Work confidently
- Recover from mistakes
- Collaborate professionally
- Build real‑world projects
15. Final Thoughts
Git may feel overwhelming at first, but you only need a few commands to be productive:
git status
git add .
git commit -m "Your message"
git push
git pull
Master these, and you already understand the core of Git and version control.
The best way to learn Git is to use it daily. Make mistakes, explore, and keep practicing.