Git & GitHub: The Complete Guide
Git and GitHub together form the foundation of modern software development, used by everyone from solo developers to Fortune 500 companies. The platform continues to evolve with new features like Copilot X (AI-assisted development) and enhanced security tools.
What is Git?
Git is a distributed version control system created by Linus Torvalds in 2005. It allows developers to:
- Track every change in their codebase
- Collaborate without overwriting each other's work
- Revert to previous versions if something breaks
- Maintain a complete history of all modifications
Key Features of Git:
- Distributed Architecture: Every developer has a full copy of the repository with complete history
- Branching & Merging: Isolate new features or bug fixes in branches before merging
- Staging Area: Lets you choose exactly which changes get committed
- Speed & Efficiency: Optimized for performance even with large codebases
What is GitHub?
GitHub is a cloud-based hosting service for Git repositories with added collaboration features. Acquired by Microsoft in 2018, it offers:
** GitHub's Core Features:**
- Repository Hosting: Cloud storage for Git projects
- Pull Requests: Code review system for team collaboration
- Issues: Bug tracking and project management
- Actions: CI/CD automation pipelines
- Pages: Free static website hosting
- Community: 100M+ developers and open-source projects
Common Workflows
- Individual Developer Flow
-
git init
- Initialize new repo -
git add
- Stage changes -
git commit
- Save changes locally -
git push
- Upload to GitHub
-Team Collaboration Flow
-
git clone
- existing repo -
git checkout -b feature-branch
- Create new branch - Make changes and commit
git push origin feature-branch
- Create Pull Request on GitHub
- Teammates review and merge
A Detailed Walkthrough of Every Concept and Command
π― Lesson 1: Setting Up Git & GitHub
- Installing Git What's Happening: Git is a distributed version control system that tracks changes to your code. Installing it gives you access to all Git commands in your terminal. Windows: The installer sets up Git Bash (a Unix-like terminal) and adds Git to your PATH. Mac/Linux: Git integrates directly with the terminal. Verify Installation:
git --version # Output: git version 2.34.1 (or similar)
Configuring Git
- Why This Matters: Git needs to know who you are to attribute commits correctly.
git config --global user.name "Your Name" # Sets author name for all commits
git config --global user.email "your@email.com" # Sets author email
git config --global init.defaultBranch main # Changes default branch from 'master' to 'main'
- Behind the Scenes: These settings are saved in ~/.gitconfig (home directory).
- Creating a GitHub Account You can create a github account by visiting the url: github.com Key Points: GitHub hosts your repositories in the cloud. Verified emails are required to create repositories.
π Lesson 2: Creating Your First Repository
- Initializing a Local Repo Step-by-Step:
mkdir my-project # Creates a directory
cd my-project # Navigates into it
git init # Initializes Git in this folder
What Happens:
A hidden .git folder is created (stores all version control data).
Your directory is now a Git repository.
- Making Your First Commit
echo "# My Project" > README.md # Creates a README file
git add README.md # Stages the file
git commit -m "Initial commit" # Saves the changes
Key Concepts:
git add: Stages changes (prepares them for commit).
git commit: Takes a snapshot of staged files.
- Connecting to GitHub Process: Create a new empty repository on GitHub (donβt initialize README). Link your local repo:
git remote add origin https://github.com/yourusername/my-project.git
git push -u origin main # Pushes to GitHub and sets 'main' as
upstream branch
What This Does:
remote add origin: Links your local repo to GitHub.
push -u origin main: Uploads commits and sets tracking.
π Lesson 3: Crafting Your GitHub Profile
- The Profile Repository Why It Works: GitHub displays the README.md from yourusername/yourusername at the top of your profile. Steps: Create a repo exactly matching your username. GitHub automatically recognizes it as your profile README.
- Writing a Dynamic README Example with Badges:
# π Hi, I'm Jane Doe
## π οΈ Tech Stack


## π Stats

Key Tools:
Shields.io: Creates badges.
GitHub Readme Stats: Live stats.
- Updating Your Profile
git add README.md
git commit -m "Update profile"
git push
πΏ Lesson 4: Branching & Merging
- Creating a Branch Why Branch? Isolates new work (e.g., features, bug fixes) from the main codebase.
git checkout -b add-feature # Creates and switches to a new branch
What Happens:
Git creates a pointer (add-feature) to the current commit.
- Making Changes in a Branch
echo "function hello() { return 'Hi!'; }" > script.js
git add script.js
git commit -m "Add hello function"
- Merging to Main
git checkout main # Switch back to main
git merge add-feature # Brings changes from 'add-feature' into 'main'
Merge Types:
Fast-forward: If no diverging changes.
3-way merge: If branches diverged (creates a new commit).
π€ Lesson 5: Collaboration Workflows
- Forking a Repository Purpose: Creates your copy of someone elseβs project (to propose changes via Pull Requests). Steps: Click "Fork" on any GitHub repo (e.g., Spoon-Knife). Clone your fork:
git clone https://github.com/yourusername/Spoon-Knife.git
- Syncing with Upstream
git remote add upstream https://github.com/original/Spoon-Knife.git # Links original repo
git pull upstream main # Fetches latest changes
Why This Matters:
Keeps your fork updated with the original project.
This is not a comprehensive tutorial on github but it helps you get started using git in your project. Git tracks changes via commits and branches while gitHub hosts repos and enables collaboration. After a couple of projects you'll realise the most used git commands are commit, push and pull. I hope this tutorial helps you to get started.
Top comments (0)