When you build a project, keeping track of changes manually—like saving files as project_v1, project_v2, and project_final—quickly becomes messy. Git solves this by acting like a smart save system for your code, while platforms like GitHub store those saves safely in the cloud so you can access or share them from anywhere.
Here is how your code moves from your computer to the cloud, step by step.
1. The Big Picture: How Git Thinks
Before running any commands, understand the three core habits behind Git:
- Local Changes (Edit Files): You write, update, or fix code inside your project folder on your computer.
- Commit Changes (Save a Snapshot): Instead of overwriting old work, Git lets you take a permanent "snapshot" of your project at that exact moment.
- Go Back Anytime (History Undo): Because every snapshot is saved in a timeline, you can inspect older versions or roll back your code if a new update breaks something.
2. Step-by-Step Git Workflow
Under the hood, Git organizes your work into four clear stages:
- Working Directory (Edit your code) This is your regular project folder on your computer. Whenever you create a new file or edit existing code, those changes stay here first.
- Staging Area (git add) Before saving a snapshot, you pick which modified files you want to include. Running git add places your selected changes into a preparation zone called the Staging Area. This keeps your history clean by letting you group related updates together.
- Local Repository (git commit) Once your changes are staged, running git commit saves them permanently into your Local Repository—a hidden history database stored inside your project folder. Each commit gets a short message explaining what you changed.
- Remote Repository (git push & git pull)
- git push uploads your saved commits from your computer to a Remote Repository (such as GitHub). This creates a cloud backup of your work and lets teammates view it.
- git pull downloads the latest updates from the remote repository back to your local machine so your code stays in sync when collaborating with others.
3. Quick Try: Commands You’ll Use Every Day
Once Git is initialized in your project folder, your daily workflow comes down to these four commands:
Bash
# 1. Stage all modified files for the next snapshot
git add .
# 2. Save the snapshot permanently with a clear message
git commit -m "Add login validation"
# 3. Upload your saved commits to GitHub
git push origin main
# 4. Download the latest changes from GitHub to your computer
git pull origin main
Why Use Git?
- Keep Your Code Safe: Every commit acts as a checkpoint, so accidental edits or bugs never wipe out working code.
- Work Together Easily: Multiple developers can work on the same project simultaneously without overwriting each other's files.
- Get Cloud Backup: Pushing your repository to GitHub ensures your project stays safe even if your computer crashes or you switch devices.
Quick Takeaway: Edit your files in the Working Directory, select them with git add, save a snapshot with git commit, and back them up to the cloud with git push.
4. Remarks: Important Things to Remember
There are a few important details that make the Git workflow easier to understand:
Git and GitHub are different.
Git is the version control system installed on your computer. GitHub is a hosting platform where you can store and collaborate on Git repositories. You can use Git without GitHub.
A commit does not automatically upload your code.
When you run git commit, the changes are saved in your local repository. They reach GitHub only when you run git push.
Check your changes before committing.
Use the following command to see which files have been modified, added, or staged:
git status
You can also inspect the actual changes before staging them:
git diff
This is particularly useful before running git add ., because that command stages all eligible changes under your current directory.
Git pull does more than download files.
git pull fetches remote changes and integrates them into your current branch, usually through a merge or rebase depending on your Git configuration. If the same lines have been changed locally and remotely, Git may report a merge conflict that you need to resolve.
5. Connecting Your Local Project to GitHub for the First Time
The daily workflow assumes that your local project is already connected to a remote repository. But how does that connection happen initially?
Follow these steps:
Step 1: Initialize Git
Inside your project directory, run:
git init
This creates the hidden .git directory that stores your project's version history.
Step 2: Set the main branch
git branch -M main
This names your current branch main.
Step 3: Connect your GitHub repository
Create an empty repository on GitHub, then copy its repository URL.
git remote add origin https://github.com/USERNAME/REPOSITORY.git
Replace USERNAME and REPOSITORY with your actual GitHub username and repository name.
Step 4: Save and upload your project
git add .
git commit -m "Initial commit"
git push -u origin main
The -u option connects your local main branch with the remote main branch as its upstream. After this setup, you can usually use git push and git pull without specifying the remote and branch every time.
You can verify the remote connection using:
git remote -v
Note: These first-time push commands assume the GitHub repository is empty. When the remote repository already contains commits, such as a README, reconcile its history with your local repository before pushing.
Final Understanding
Git manages your project's history locally, while GitHub hosts a copy of that repository remotely.
Remember these five commands:
| Command | Purpose |
|---|---|
git status | Check current changes |
git add | Select changes for the next commit |
git commit | Save changes locally |
git push | Upload commits to the remote |
git pull | Fetch and integrate remote changes |
Once you understand how these commands work together, managing project versions and collaborating with other developers becomes much easier.



