DEV Community

ClintWithK
ClintWithK

Posted on

Understanding Git and GitHub: Pushing, Pulling, and Tracking Code (Beginner-Friendly Guide)

As you grow in your tech journey, one tool you will definitely encounter early is Git. At first, it might feel confusing or even intimidating, but once you understand why it exists and how it works, it becomes one of the most powerful tools in your workflow.

In this article, we’ll cover:

  • What Git is and why version control is important
  • How to push code to GitHub
  • How to pull code from GitHub
  • How to track changes using Git

Let’s break it down step by step.


What Is Git and Why Is Version Control Important?

Git is a version control system. In simple terms, it helps you:

  • Track changes in your code
  • Save different versions of your project
  • Collaborate with others without overwriting each other’s work

Imagine working on a project and accidentally deleting a file that worked perfectly yesterday. Without Git, that’s a nightmare. With Git, you can go back in time and restore previous versions.

Why Version Control Matters

Version control allows you to:

  • See what changed, when, and by who
  • Work on features safely
  • Experiment without fear
  • Collaborate with teams efficiently

GitHub, on the other hand, is a platform that hosts Git repositories online, making it easier to store, share, and collaborate on code.


Initial Setup (Quick Recap)

Make sure you have:

  • Git installed
  • A GitHub account
  • SSH set up (as covered in the previous article)

Open your terminal using Ctrl + Alt + T.


Step 1: Initialize a Git Repository

Navigate to your project folder:

cd project-folder
Enter fullscreen mode Exit fullscreen mode

Initialize Git:

git init
Enter fullscreen mode Exit fullscreen mode

This creates a hidden .git folder that Git uses to track your project.

Step 2: Tracking Changes Using Git

Check Project Status

git status
Enter fullscreen mode Exit fullscreen mode

This shows:

  • Untracked files

  • Modified files

  • Files ready to be committed

Add Files to Staging

To track all files:

git add .
Enter fullscreen mode Exit fullscreen mode

Or add a specific file:

git add filename.py
Enter fullscreen mode Exit fullscreen mode

Commit Your Changes

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

A commit is like saving a snapshot of your project at that moment.

Step 3: Push Code to GitHub

Create a Repository on GitHub

  • Log in to GitHub

  • Click New repository

  • Give it a name

  • Do not initialize with README

  • Copy the SSH repository URL

Connect Local Repo to GitHub

git remote add origin git@github.com:username/repository-name.git
Enter fullscreen mode Exit fullscreen mode

Verify:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Push Your Code

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

Your code is now live on GitHub

Step 4: Pull Code from GitHub

Pulling allows you to fetch and update your local code with changes from GitHub.

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This is especially important when:

  • Working with others

  • Switching between machines

  • Updating your local copy

Step 5: Viewing and Tracking Changes

View Commit History

git log
Enter fullscreen mode Exit fullscreen mode

See File Changes

git diff
Enter fullscreen mode Exit fullscreen mode

Quick Overview

git status
Enter fullscreen mode Exit fullscreen mode

These commands help you understand what changed, what’s staged, and what’s committed.

A Typical Git Workflow

Here’s how things usually flow:

  • Make changes to your code

  • Check status

git status
Enter fullscreen mode Exit fullscreen mode
  • Add changes
git add .
Enter fullscreen mode Exit fullscreen mode
  • Commit
git commit -m "Describe what you changed"
Enter fullscreen mode Exit fullscreen mode
  • Push to GitHub
git push
Enter fullscreen mode Exit fullscreen mode

Simple, repeatable, and powerful.

Final Thoughts

Git is not just a tool — it’s a safety net for your code. Once you get comfortable with pushing, pulling, and tracking changes, your confidence as a developer grows significantly.

If you’re just starting out, don’t rush mastery. Focus on understanding the basics and practicing regularly.

What’s Next?

            Practice! Practice! Practice! 
Enter fullscreen mode Exit fullscreen mode

Happy coding!

Top comments (0)