DEV Community

Wangeci Ndovu
Wangeci Ndovu

Posted on

Understanding Git: How to Track Changes, Push, and Pull Code Like a Pro

code 101

When you start writing code, you quickly realize something:
files change, mistakes happen, and things break

So how do professional developers keep track of what changed, how it changed, how to correct it or in words, how to go back in time when something breaks?

This article simply explains:

  • How Git tracks changes
  • How to push code to GitHub
  • How to pull data from GitHub

beginner friendly

What is Version Control

Version control is a system that keeps track of:

  • Every change you make to your code

  • When the change happened

  • Who made the change

  • What exactly was modified

Think of it like Google Docs history for your code.

If your code breaks, Git lets you correct it to a working version.

Git also helps you collaborate with other like minded individuals in shared projects.

What is GitHub?

GitHub is a cloud platform where Git repositories are stored online.
You use
Git on your computer
GitHub to back it up and share it with others

How to create a Git Repository

A repository is a folder that Git tracks.

git init
Enter fullscreen mode Exit fullscreen mode

This creates a hidden .git folder inside your project.
Now Git is watching this directory.

Save a Version (Commit)

A commit is a snapshot of your project.

git commit -m "Add file"
Enter fullscreen mode Exit fullscreen mode

Now Git has stored that version forever.
You can always go back to it.

Push Code to GitHub

First connect your project to GitHub:

git remote add origin git@github.com:yourname/yourrepo.git

Push:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Note: The default branch name is often main. If yours is "master"

use

git push -u origin master.
Enter fullscreen mode Exit fullscreen mode

Your code is now safely stored online.

Pull Code from GitHub

If someone else updates the repository, or you work from another computer:
Navigate to your local repository directory using the command

cd
Enter fullscreen mode Exit fullscreen mode

For example, if your repository is in a folder named Mombasa then,

cd Mombasa
Enter fullscreen mode Exit fullscreen mode

Ensure you are on the correct branch by using the command

git status
Enter fullscreen mode Exit fullscreen mode

Pull the latest changes from the remote repository using the git pull command

git pull
Enter fullscreen mode Exit fullscreen mode

This downloads the latest changes into your project.

How Git Tracks Changes

When you edit a file:

git status
Enter fullscreen mode Exit fullscreen mode

Git will show:

modified: Mombasa

To save the change:

git add Mombasa
Enter fullscreen mode Exit fullscreen mode

then

git commit -m "Mombasa"
Enter fullscreen mode Exit fullscreen mode

Git stores only what changed, not the entire file.

This makes Git fast and powerful.

Why Git is a Superpower

With Git you can

  • Undo mistakes

  • Work on features safely

  • Collaborate with others

  • Track project history

  • Work on multiple versions

This is why every professional developer uses Git.

conclusion

Git is not just a tool β€” it is how software is built.

Once you understand:

  • add

  • commit

  • push

  • pull

You can work on any real-world engineering project.

Top comments (0)