DEV Community

Karen Langat
Karen Langat

Posted on

Git for Beginners: How to Track Changes, Push & Pull Code

If you're new to programming, you've probably heard phrases like "push your code," or "pull the latest changes," and wondered, what does all this actually mean?
This article explains Git and version control in simple terms. It also explains how to track changes, push code, and pull updates step by step.

What Is Version Control

Version control is a system that tracks changes to your code over time.
It allows you to see what changed, go back to older versions, and allows multiple people to work on the same project safely.
Git is the most popular version control system used by developers today.

Key Git Concepts

  • Repository (Repo)
    A repository is a folder that Git is tracking. It contains your project files plus a hidden .git folder that stores change history.

  • Local vs Remote Repository

  • A Local repo is stored on your computer. It is where all development work, such as committing and branching, takes place

  • A Remote repo is hosted on a separate server (like GitHub or GitLab) and serves as a shared workspace for team collaboration
    You write code locally, then push it to the remote repo.

  • Commit
    A commit is a saved snapshot of your code at a point in time. It is a way for Git to remember the current state of your project.

  • Push & Pull
    Push - send your commits to GitHub
    Pull - get the latest commits from GitHub

Installing Git

First, check if Git is installed by opening your terminal and typing:

git --version
Enter fullscreen mode Exit fullscreen mode

If not installed, download from https://git-scm.com and install using default settings.

Using Git

Step 1: Create or Initialize a Git Repository

Option A: Start Git in an Existing Project

cd your-project-folder
git init
Enter fullscreen mode Exit fullscreen mode

This tells Git to start tracking changes in the folder.

Option B: Clone an Existing Repo

git clone https://github.com/username/repository-name.git
Enter fullscreen mode Exit fullscreen mode

This downloads the project and automatically sets up Git.

Step 2: Check File Status

Run:

git status
Enter fullscreen mode Exit fullscreen mode

This shows which files are new, which were modified, and which are ready to commit.

Step 3: Track Changes (Staging Files)

Before committing, you must stage files. Staging prepares changes in your working directory to be included in the next commit
To stage a Single File:
git add index.html
To stage All Changes:

git add .
Enter fullscreen mode Exit fullscreen mode

Step 4: Commit Your Changes

Create a commit with a message:

git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

Good commit messages are short and describe what changed, not how.

Step 5: Push Code to GitHub

First, make sure your repo is connected to GitHub:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Then push:

git push origin main
Enter fullscreen mode Exit fullscreen mode

This sends your commits to GitHub and makes your code visible online.

Step 6: Pull Latest Changes

If someone else updated the repo (or you changed it on GitHub):

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This fetches new commits and updates your local files. Always pull before starting new work to avoid conflicts.

** Understanding the Git Workflow (Big Picture)
Here's the typical cycle:
Write code
Check status: git status
Stage changes: git add .
Commit: git commit -m "Meaningful message"
Push: git push
Repeat

Viewing Change History

See past commits:

git log
Enter fullscreen mode Exit fullscreen mode

This helps you understand project history, debug issues, and roll back changes if needed.

Common Beginner Mistakes (And How to Avoid Them)

  • Forgetting to Pull: Always pull before starting work to get the latest changes.
  • Huge Commits: Commit small, logical changes instead of everything at once.
  • Vague Messages: Write clear commit messages that explain what you did.

Why Git Matters (Even for Solo Developers)

Even if you work alone, Git:

  • Protects you from accidental mistakes
  • Lets you experiment safely
  • Makes collaboration easier later
  • Is required for most developer jobs

Conclusion

Git might seem confusing at first, but once you understand the basic workflow of staging, committing, pushing, and pulling, it becomes easier to navigate.
Git is a skill that builds with repetition. Start practicing with a simple project today, and these commands will become second nature before you know it.

Top comments (0)