Back to Blog

Basic Things You Need to Know About Git and GitHub

Basic Things You Need to Know About Git and GitHub

In modern software development, version control is an absolute necessity. Whether you are building a simple mobile app or a complex B2B SaaS platform, tracking changes, collaborating with teammates, and managing deployment workflows require a solid understanding of Git and GitHub.

While they are often mentioned together, they are two distinct tools that serve complementary purposes.


1. Git vs. GitHub: What's the Difference?

Understanding the distinction between these two is the first step toward mastering version control.

  • Git is a Version Control System (VCS) that runs locally on your machine. It tracks the history of your files, allows you to create independent branches, and lets you revert back to previous states of your codebase. It doesn't require an internet connection to work.
  • GitHub is a cloud-based hosting service for Git repositories. It provides a graphical interface, collaboration tools (like Pull Requests and Code Reviews), project management features, and integration with deployment platforms.

Analogy: Think of Git as the local word processor (like Microsoft Word tracking changes) and GitHub as the cloud storage and collaboration platform (like Google Docs or OneDrive where you share it with your team).


2. Core Git Concepts You Must Know

Before running commands in your terminal, you need to understand how Git views your project file structure. Git manages files across three distinct local zones and one remote zone:

  1. Working Directory (Workspace): This is your local folder where you are actively modifying, deleting, or adding files using your IDE.
  2. Staging Area (Index): A temporary preview zone. This is where you prepare and select specific changes that you want to include in your next snapshot (commit).
  3. Local Repository (HEAD): The local database on your machine (inside the hidden .git folder) where Git permanently saves your project's snapshots as commits.
  4. Remote Repository: The hosted version of your repository on the cloud (e.g., GitHub) that allows synchronization across different team members.

3. Essential Git Commands Workflow

A standard, production-ready development cycle relies heavily on a handful of foundational commands.

Phase A: Starting a Project

To start tracking a new project or download an existing one:

  • git init — Initializes a brand new, empty local Git repository in your current directory.
  • git clone <repository-url> — Downloads an existing repository from GitHub to your local machine, automatically setting up the remote tracking pointers.

Phase B: Saving Changes

The core loop of saving work locally involves checking status, staging, and committing:

  • git status — Displays the current state of your working directory and staging area (shows tracked, untracked, and modified files).
  • git add <file-name> — Moves specific modified files from the Working Directory to the Staging Area. Use git add . to stage all local modifications at once.
  • git commit -m "Your descriptive commit message" — Takes a snapshot of your staged changes and records it permanently into the Local Repository history. Always use clear, imperative commit messages (e.g., git commit -m "Fix student directory query timeout").

Phase C: Branching & Collaboration

Branching allows you to isolate new features or bug fixes from the stable codebase.

  • git branch — Lists all local branches in your repository.
  • git checkout -b <branch-name> — Creates a new branch and immediately switches your workspace to it. (In newer Git versions, you can also use git switch -c <branch-name>).
  • git merge <branch-name> — Combines the history and changes of the specified branch into your current active branch.

Phase D: Synchronizing with GitHub

Once your local commits are structured, you sync them with the cloud:

  • git remote add origin <repository-url> — Links your local repository to a remote GitHub repository for the first time.
  • git push -u origin <branch-name> — Uploads your local branch commits to the remote GitHub repository and sets the default upstream tracking branch. Subsequent pushes only require git push.
  • git pull — Fetches the latest updates from the remote GitHub repository and instantly merges them into your active local branch.

4. Key GitHub Features for Collaboration

GitHub extends Git's power by acting as the central hub for team collaboration and code quality management.

Repositories (Repos)

A repository is the digital storage space for your project. It contains all project files, documentation (like README.md), and the entire commit history. Repositories can be public (visible to the world) or private (restricted to specific collaborators).

Pull Requests (PRs)

A Pull Request is a formal submission on GitHub proposing that changes from one branch be merged into another (usually merging a feature branch into main). PRs provide an interface for:

  • Comparing line-by-line code differences (Diffs).
  • Leaving inline comments or requested changes during code reviews.
  • Running automated tests or builds before finalizing the merge.

Forking vs. Cloning

  • Cloning creates a linked copy of a repository directly on your local machine. You must have write permissions to push back to it.
  • Forking creates an entirely independent, server-side copy of someone else's repository under your own GitHub account. This is heavily used in open-source development, allowing you to make changes freely and submit a Pull Request back to the original project later.

Issues and Project Boards

GitHub includes built-in project management tools. You can log bugs, suggest new features, and organize tasks using Kanban-style boards directly alongside your code.


5. Summary of a Typical Day-to-Day Git Workflow

  1. Pull latest changes from the main codebase to stay up-to-date: git pull origin main
  2. Create a feature branch to isolate your work: git checkout -b feat/add-payment-gateway
  3. Write code and test your changes locally.
  4. Stage and commit your progress with clear messages:
    git add .
    git commit -m "Implement Stripe webhook handler for subscription renewals"
    
  5. Push to GitHub: git push origin feat/add-payment-gateway
  6. Open a Pull Request on GitHub for code review.
Click to start a conversation on WhatsApp with Shotech Enterprises