DEV Community

Dennis Ogaka
Dennis Ogaka

Posted on

Git for Beginners

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 .git folder that stores version history

There are two types:

  1. Local repository → on your computer
  2. Remote repository → online (for example, on GitHub)

4. How Git Tracks Changes

Git tracks changes in three main areas:

1. Working Directory

This is where you edit files normally. Example:

index.html
style.css
Enter fullscreen mode Exit fullscreen mode

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.

Command:

git add filename
Enter fullscreen mode Exit fullscreen mode

Or add everything:

git add .
Enter fullscreen mode Exit fullscreen mode

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.

Command:

git commit -m "Describe what changed"
Enter fullscreen mode Exit fullscreen mode

A commit includes:

  • The changes
  • Your message
  • Date and author

Git Change Flow (Very Important)

Edit files Stage changes Commit

Enter fullscreen mode Exit fullscreen mode

5. Installing Git

Check if Git is installed:

git --version
Enter fullscreen mode Exit fullscreen mode

If not installed:

  • Windows: Download from git-scm.com
  • macOS: Install via Homebrew or Xcode tools
  • Linux: Use your package manager

6. Creating Your First Git Repository

Navigate to your project folder:

cd my-project
Enter fullscreen mode Exit fullscreen mode

Initialize Git:

git init
Enter fullscreen mode Exit fullscreen mode

Now your folder is a Git repository.

7. Checking File Status

Use this command often:

git status
Enter fullscreen mode Exit fullscreen mode

It tells you:

  • Which files are modified
  • Which files are staged
  • What is ready to commit

8. Making Your First Commit

Step 1: Add files to staging

git add .
Enter fullscreen mode Exit fullscreen mode

Step 2: Commit changes

git commit -m "Initial project setup"
Enter fullscreen mode Exit fullscreen mode

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).

Example:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Meaning:

  • Push → send changes
  • origin → remote repository
  • main → branch name

You use push when:

  • You want to upload your work
  • You want others to see your changes

What Is Pull?

Pull downloads the latest changes from the remote repository to your local machine.

Example:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

You use pull when:

  • Someone else updated the code
  • You want 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 (or master) → stable code
  • Feature branches → new features or experiments

Create a new branch:

git branch feature-login
Enter fullscreen mode Exit fullscreen mode

Switch to it:

git checkout feature-login
Enter fullscreen mode Exit fullscreen mode

Or both in one command:

git checkout -b feature-login
Enter fullscreen mode Exit fullscreen mode

Branches let you:

  • Experiment safely
  • Avoid breaking main code
  • Work in parallel with others

11. A Simple Daily Git Workflow

Here is a beginner-friendly workflow you can follow every day:

  1. Pull latest changes
git pull origin main
Enter fullscreen mode Exit fullscreen mode
  1. Make code changes

  2. Check status

git status
Enter fullscreen mode Exit fullscreen mode
  1. Stage changes
git add .
Enter fullscreen mode Exit fullscreen mode
  1. Commit changes
git commit -m "Add login validation"
Enter fullscreen mode Exit fullscreen mode
  1. Push to remote
git push origin main
Enter fullscreen mode Exit fullscreen mode

12. Viewing Commit History

See past commits:

git log
Enter fullscreen mode Exit fullscreen mode

This helps you:

  • Understand project history
  • Identify when bugs were introduced
  • Revert changes if needed

13. Common Beginner Mistakes

  1. Forgetting to commit changes

  2. Writing unclear commit messages

  3. Not pulling before pushing

  4. Editing directly on the main branch

  5. 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

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.

Top comments (0)