DEV Community

Githinji Victor Maina
Githinji Victor Maina

Posted on

A Beginner’s Guide to Git Bash and GitHub: Pushing, Pulling, and Version Control

Introduction
If you are starting your journey in tech, you have probably heard the words "Git" and "GitHub" thrown around constantly. Maybe you have even installed them but aren't quite sure how they actually work.

In this guide, I will walk you through the absolute essentials: how to set up your environment, track changes, and push your code to the internet. By the end of this article, you will understand the core workflow that professional developers use every day.

What is Version Control?

Before we type any commands, we need to understand Version Control.

Imagine you are writing a university essay. You might have files like:

  • Essay_Final.docx
  • Essay_Final_v2.docx
  • Essay_Final_REALLY_DONE.docx

This is messy. Git solves this by tracking changes to a single file over time. It allows you to save "snapshots" (called commits) of your project history. If you make a mistake, you can simply revert to an earlier snapshot.

  • Git: The tool installed on your laptop (Local).
  • GitHub: The website where you upload your code (Remote).

Step 1: Configuration (The One-Time Setup)
Since you have already installed Git Bash, the first thing you must do is introduce yourself to Git. This ensures that every "save" you make is tagged with your name.

Open Git Bash and run these two commands:

To check if it worked, type:

Step 2: Initializing a Repository
To start tracking a project, you need to initialize it. Open Git Bash in your project folder and run:

This command creates a hidden .git folder. It tells Git: "Start watching this directory for changes.

Step 3: The Staging Area & Committing
Git doesn't save changes automatically. You have to tell it exactly what to save. This is a two-step process: Staging and Committing.

1. Check Status
First, let's see which files Git has noticed are new or changed:

If your text is red, it means the file is not yet staged.

2. Stage Changes (git add)
Think of this as putting a letter in an envelope. You are preparing the file to be sent.

(The . tells Git to add ALL changed files at once).
3. Commit Changes (git commit)
Now, we seal the envelope. This saves the snapshot permanently.

Step 4: Connecting to GitHub
Now that your code is saved locally, let's put it on the internet.

  1. Go to GitHub.com and create a new repository (click the + icon).
  2. Copy the URL provided (it looks like https://github.com/username/repo.git).
  3. Back in your terminal, link your local folder to GitHub:

Pushing Code
"Pushing" uploads your commits from your computer to GitHub.

origin: The nickname for your online repository.
main: The branch you are working on.

If you refresh your GitHub page, you will now see your files!

Step 5: Pulling Changes
If you work on a team, or if you edit a file directly on the GitHub website, your laptop will be "behind" the online version.
To update your local computer, we use Pull:

This downloads the latest changes and merges them into your code automatically.

Bonus: Branching Basics
As you get advanced, you won't always work on the **main **code directly. You will use Branches.
A branch is like a parallel universe where you can test new features without breaking the main project.

  • Create a branch: git branch feature-login
  • Switch to it: git checkout feature-login
  • Merge it back: git merge feature-login

Summary of Commands
Here is a cheat sheet for your daily workflow:

Conclusion
Version control is a superpower for developers. It saves you from losing work and helps you collaborate with others. Start by mastering add, commit, and push, and you will be well on your way to becoming a professional developer.
Happy Coding!

Top comments (0)