DEV Community

Jobby-John
Jobby-John

Posted on

Understanding Git in a simple and elaborate way.

*Understanding Git Version Control: How I Push, Pull, and Track Changes *

When I first started programming, I kept overwriting files and losing progress. Sometimes I would break my project and have no way to go back. That’s when I discovered Git — a version control system that completely changed how I manage code.

In this article I will explain how I track changes, commit, push, and pull code using Git in a simple way.

What Is Git and Why Do I Use It?

Git is a tool that tracks changes in my project files over time. I use it to:

  1. Save different versions of my code
  2. Restore old working versions
  3. Collaborate with teammates
  4. Upload my projects to GitHub safely

** How Git Works **

This is the basic workflow I follow every day:

  1. I edit files on my computer
  2. I stage the changes
  3. I commit them. This is like saving them as a snapshot.
  4. I push them to GitHub
  5. I pull updates when needed

Step 1: Installing Git

Before using Git, I make sure it’s installed.

I check by typing on the terminal on my computer

git --version

If Git is not installed, I download it from:

https://git-scm.com

Step 2: Setting Up Git (One-Time Setup)

The first time I use Git, I tell it who I am for instance my name is chege and my email is chegejohn2030@gmail.com

git config --global user.name "Chege"
git config --global user.email "chegejohn2030@gmail.com"

This information is key as it appears in my commit history so others can see who made each change.

Step 3: Creating or Cloning a Repository. In this step there are two options available

Option 1 — Initialize Git in My Project

If I already have a project folder, I open it and run:

git init

This creates a hidden .git folder that starts tracking my project.

Option B — Clone an Existing GitHub Project

If the project already exists online, I use:

git clone https://github.com/username/repository-name.git

This downloads the project directly to my computer.


Step 4: Checking File Status (Tracking Changes)

Whenever I modify files, I check what Git sees by running:

git status

This tells me:

  1. Which files were changed
  2. Which files are staged
  3. Which files are new ** Understanding File States**
  • Red files → Changed but not staged
  • Green files → Ready to be committed

Step 5: Staging Changes

Before saving changes permanently, I move them to the staging area.

To add one file:

git add index.html

To add everything:

git add .

Staging lets me choose exactly what I want to include in my next commit.

** Step 6: Committing Changes (Saving a Snapshot)**

A commit is like taking a snapshot of my project at that moment.

I save my changes using:

git commit -m "Added homepage layout"

How to Write Good Commit Messages

I always try to:

  • Keep it short
  • Be specific
  • Describe what changed

Clear messages help future me (and teammates).


Step 7: Pushing Code to GitHub

After committing, I upload my code to GitHub using push:

git push origin main

Here’s what this means:

  • origin → The remote GitHub repository
  • main → The main branch of the project

Now my code is backed up online.

Step 8: Pulling Updates From GitHub

When someone else updates the project or when I switch devices I use pull:

git pull origin main

This downloads the newest changes and merges them into my local project.

** Push vs Pull**

Action What I Use It For
Push Upload my changes to GitHub
Pull Download new updates

Viewing Project History

To see all saved versions of my project, I run:

git log

This shows:

  1. Commit IDs
  2. Author names
  3. Dates
  4. Messages It helps me track progress and debug issues.

*Understanding Branches *

Branches allow me to work on new features without breaking the main project.

Creating and Switching to a Branch

Instead of two commands, I usually use one:
git checkout -b new-feature

This:

  1. Creates a branch
  2. Switches to it immediately

Merging a Branch

When the feature is ready, I merge it back:

git checkout main
git merge new-feature

Some beginner mistakes that I learned to avoid

Forgetting to commit

I always commit before pushing.

Not pulling first

I pull updates before starting work to avoid conflicts.

Using unclear commit messages

Clear messages save time later.

Uploading sensitive files

I never commit passwords, API keys, or .env files.

Git Command Cheat Sheet

Command What It Does
git init Start a Git project
git status Check file changes
git add . Stage all files
git commit -m Save snapshot
git push Upload code
git pull Download updates
git log View history

Conclusion

Learning Git completely changed how I code. I no longer worry about losing progress, breaking projects, working with teammates, making mistakes. This is because Git lets me track, restore, collaborate, and grow confidently

Top comments (0)