DEV Community

Cover image for Git for Beginners: Pushing, Pulling and Tracking Code Without the Stress
Kinywa
Kinywa

Posted on

Git for Beginners: Pushing, Pulling and Tracking Code Without the Stress

If you’re just getting into coding, chances are you’ve heard people casually throw around words like git, commit and github and thought:

“Yeah… I’ll figure that out later”

Good news: now is later and git isn’t as scary as it sounds.

So… What exactly Is git?

Git is a version control system. That's just a fancy way of saying:

Git keeps track of changes in your code over time

Think of git like a save system for your project, except:

  • Every save has a message
  • You can go back to any previous version
  • You can see what changed, when and why

Why version control is a big deal

Version control is important because:

  • Code breaks
  • Features change
  • Bugs appear out of nowhere
  • Teams work on the same files

With git, you can: Roll back to a working version, experiment without fear, collaborate without overwriting someone else’s work and understand how your project evolved.

Basically, git lets you make mistakes safely and that’s huge.

Installing git

First things first, install git:

👉 https://git-scm.com/

After installing, check that it works on cmd:

git --version
Enter fullscreen mode Exit fullscreen mode

If you see a version number, you’re good to go 👍

How to push code to github

Let’s walk through a real-world flow.

Create a github repository

On github:

  1. Click new repository
  2. Give it a name (e.g. your-first-repository)
  3. Click create repository

That’s your online home for the project.

Setting Up Your Git Username and Email

Before you start committing code, Git needs to know who you are. If you don’t set this up, Git will eventually stop you with an error like:

Please tell me who you are.

This information is attached to every commit you make, so GitHub and other developers can see who made each change.

Run these commands:

git config --global user.name
git config --global user.email
Enter fullscreen mode Exit fullscreen mode

Set your git username

git config --global user.name "Your Name"
git config --global user.email "youremail@gmail.com"
Enter fullscreen mode Exit fullscreen mode

Run & you are all set

git config --global --list
Enter fullscreen mode Exit fullscreen mode

Initialize git in your project - This tells git: Hey, start tracking this project.

git init
Enter fullscreen mode Exit fullscreen mode

Add files to git - This means: I want git to track all current changes.

git add .
Enter fullscreen mode Exit fullscreen mode

Commit your changes - A commit message should explain what you changed not your life story, hehe lol.

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

Connect your project to github - This links your local project to github.

git remote add origin https://github.com/your-username/your-first-repository.git
Enter fullscreen mode Exit fullscreen mode

Push your code - Boom 💥 Your code is now on GitHub.

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

How to pull code from github

Pulling just means - “Give me the latest version from github.”

Run this inside your project:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

How to track changes with git

This is where git really shines. Check the status of your project

git status
Enter fullscreen mode Exit fullscreen mode

If you ever feel lost, run

git status
Enter fullscreen mode Exit fullscreen mode

See exactly what changed

git diff
Enter fullscreen mode Exit fullscreen mode

This shows line-by-line changes before you commit.

View commit history

git log
Enter fullscreen mode Exit fullscreen mode

This shows: past commits, messages, dates and authors

Git feels confusing at first because it’s different, not because it’s impossible.

Once you understand:
add - stage
commit - save
push - upload
pull - download

…it starts to click. If you’re learning git, you’re already doing the right thing. Stick with it.

Code! Add! Commit! 🚀

Top comments (1)

Collapse
 
kinyywa-data-analyst profile image
Kinywa • Edited

If you’re learning to code and git feels confusing or intimidating, you’re not alone.
This post breaks down git and github the easy way.