Git and GitHub Mastery: From Basics to Collaboration

A comprehensive 152-minute tutorial covering Git fundamentals (version control, commits, branches), GitHub essentials (repositories, pull requests, forking), GitHub Desktop GUI, VS Code integration, and multi-user workflows with real-world examples.

What is Git and Why It Exists

Git solves the collaboration problem

Git is a version control system created by Linus Torvalds in April 2005 to track who changed which line of code, when, and why. Before Git, developers working on Linux couldn't determine who made breaking changes, leading to constant conflicts and confusion.

Centralized vs. Distributed version control

Centralized systems store all code on one server; if the server goes down or you lose internet, you cannot work. Distributed systems like Git give every developer a complete copy of the project history, allowing offline work and eliminating single points of failure.

Git is now ubiquitous

Approximately half of the world's software projects use Git today. It became so popular that Microsoft acquired GitHub for $8 billion in 2018.

Git vs. GitHub: Understanding the Difference

Git is the tool, GitHub is the platform

Git is software that tracks code changes locally on your computer. GitHub is an online platform (created in April 2008) where you host Git repositories remotely so others can access and collaborate on your code.

GitHub Desktop simplifies Git workflows

GitHub Desktop is a GUI application that eliminates the need to memorize terminal commands. It makes Git accessible to non-technical users by providing a visual interface for commits, branches, and merges.

Git Installation and Setup

Installing Git on Windows, Mac, and Linux

On Windows, download from git-scm.com and run the installer. On Mac, use Homebrew (brew install git) after installing Homebrew. On Linux, use apt (apt-get install git). After installation, verify with 'git --version'.

Configure Git with your identity

Run 'git config --global user.name "Your Name"' and 'git config --global user.email "your@email.com"' so that every commit is attributed to you. This is essential for collaboration.

Core Git Concepts: The Four Locations

Code moves through four locations in Git

Working Directory (your local files) → Staging Area (files ready to commit) → Local Repository (committed snapshots on your machine) → Remote Repository (code on GitHub). You control this flow with git add, git commit, git push, and git pull.

The Big Four Git Commands

git init: Initialize a repository

Converts a folder into a Git repository by creating a hidden .git folder. This folder contains all version control data. Run 'git init' once per project.

git status: Check repository state

Shows which files are untracked, modified, or staged. Run it frequently to understand what Git sees. Output includes branch name, commits, and file status.

git add: Stage files for commit

Moves files from working directory to staging area. Use 'git add filename' for one file or 'git add .' to stage all changes. You can selectively stage only the files you want to commit.

git commit: Save a snapshot

Creates a checkpoint with a message describing changes. Use 'git commit -m "message"'. Good commit messages use present tense (e.g., 'Add login feature' not 'Added login feature').

Viewing Commit History

git log shows all commits

Displays full commit history with hash, author, date, and message. Use 'git log --oneline' to see commits in one line per entry, making it easier to scan history.

Branching: Working Independently

Branches allow parallel development

A branch is a pointer to a commit. Create a feature branch to work independently without affecting the main branch. If the feature fails, delete the branch; if it succeeds, merge it back.

Branching best practices

Create one branch per feature. Use descriptive names (e.g., 'feature/user-login'). Keep branches short-lived; merge as soon as work is complete. Delete merged branches. Never develop directly on main.

Merging and Merge Conflicts

Merging combines branches

Use 'git merge branch-name' to integrate a feature branch into main. Git automatically combines changes if they don't conflict. A merge commit is created to record the merge.

Merge conflicts require manual resolution

Conflicts occur when the same file is edited differently in two branches. Git marks conflicting sections with <<<<<<, ======, and >>>>>>. You must manually choose which version to keep, then commit the resolution.

Stashing: Temporary Storage

Stash saves work without committing

Use 'git stash' to temporarily save uncommitted changes and clean your working directory. Retrieve them later with 'git stash pop'. Useful when you need to switch branches urgently without committing incomplete work.

Rebasing: Keeping History Clean

Rebase replays commits on a new base

Instead of merging (which creates a merge commit), rebasing replays your branch's commits on top of the target branch. This keeps history linear and avoids merge commit clutter. Use 'git rebase main' from your feature branch.

When to merge vs. rebase

Use merge to preserve history and show that branches existed. Use rebase to keep history clean and linear. Many organizations prefer rebase to avoid merge commit bloat.

Tagging: Marking Releases

Tags mark important commits

Use tags to mark releases (e.g., v1.0, v1.1). Two types: annotated tags (with message) and lightweight tags (just a name). Create with 'git tag -a v1.0 -m "Release 1.0"' or 'git tag v1.0'.

Ignoring Files with .gitignore

Prevent tracking of unnecessary files

Create a .gitignore file and list files/folders to ignore (e.g., .env, node_modules/, build/). Git will not track these files. Essential for hiding secrets, build artifacts, and dependencies.

Git doesn't track empty directories

To include an empty directory, add a .gitkeep file inside it. This allows Git to track the directory structure without actual content.

GitHub: Hosting and Collaboration

Create and manage repositories on GitHub

Sign up at github.com, create a new repository, choose public or private, optionally add README and .gitignore. Clone to your machine with 'git clone <url>' and start pushing code.

Push and pull to sync with GitHub

Use 'git push origin main' to upload commits to GitHub. Use 'git pull origin main' to download changes from GitHub. 'git fetch' downloads without merging; 'git pull' downloads and merges.

Collaborate with pull requests

Create a pull request (PR) to propose merging a branch into main. Team members review, comment, and approve before merging. PRs enable code review and discussion before integration.

GitHub Desktop: GUI Alternative

GitHub Desktop eliminates command-line complexity

Download from desktop.github.com. Provides visual interface for cloning, committing, branching, and pushing. Ideal for beginners or those uncomfortable with terminal commands. Handles authentication automatically.

Workflow in GitHub Desktop

Clone repository → make changes → stage files (click +) → write commit message → commit to branch → publish branch → create pull request. All done through GUI without terminal.

VS Code Integration

Git features built into VS Code

VS Code has built-in Git support. Stage files, write commit messages, and push directly from the editor. Use the Source Control panel (Ctrl+Shift+G) to manage commits without terminal.

Git Graph extension visualizes history

Install 'Git Graph' extension in VS Code to see a visual representation of commits and branches. Helps understand project history and branch relationships at a glance.

Forking and Contributing

Fork creates a personal copy of someone else's repo

Click 'Fork' on GitHub to create your own copy of a repository. You have full control over your fork. Use forks to contribute to open-source projects or experiment without affecting the original.

Pull requests enable open-source contributions

After forking and making improvements, create a pull request to propose merging your changes into the original repository. Maintainers review and decide whether to accept. Only contribute meaningful changes.

Multi-User Workflows

Collaboration workflow: issues, branches, PRs

Create issues to assign tasks. Team members create branches for each issue. After completing work, they push and create pull requests. Maintainer reviews and merges. Issues are closed when merged.

Handling merge conflicts in teams

When two team members edit the same file, conflicts arise. Communicate with teammates, resolve conflicts manually by choosing which changes to keep, then commit the resolution.

Git Best Practices

Write meaningful commit messages

Use present tense ('Add login feature' not 'Added login feature'). Be specific about what changed and why. Good messages help future developers understand history.

Never push secrets to GitHub

Never commit passwords, API keys, or database credentials. Use .env files and add them to .gitignore. If secrets are exposed, they can be exploited by attackers.

Review code before committing

Always check what you're about to commit. Use 'git status' and 'git diff' to review changes. Avoid committing unintended changes.

Keep branches short-lived

Merge feature branches into main as soon as work is complete. Long-lived branches cause integration problems and merge conflicts.

Future of Git: AI Integration

AI can generate commit messages

Tools like GitHub Copilot can automatically generate meaningful commit messages based on your code changes. This saves time and ensures consistency.

AI assists with code review and suggestions

AI can suggest improvements, catch bugs, and help with code generation. Pair programming with AI is becoming more common in modern development workflows.

Notable quotes

Git is a distributed version control system that is fast, reliable, and very easy to use. — CodeWithHarry
Never push secrets like passwords or API keys to GitHub. Use .env files and add them to .gitignore. — CodeWithHarry
Write meaningful commit messages in present tense. Say 'Add login feature' not 'Added login feature'. — CodeWithHarry

Action items

  • Install Git on your machine (Windows/Mac/Linux) and verify with 'git --version'
  • Configure Git identity: git config --global user.name and git config --global user.email
  • Create a test repository locally using 'git init' and practice the four main commands (init, status, add, commit)
  • Create a GitHub account and push your test repository to GitHub
  • Practice branching: create a feature branch, make commits, and merge back to main
  • Create a .gitignore file and add files you want to exclude from tracking
  • Install GitHub Desktop and practice the same workflow through the GUI
  • Collaborate with a friend: fork their repository, make changes, and create a pull request
  • Practice resolving merge conflicts by editing the same file in two branches and merging
  • Install Git Graph extension in VS Code and visualize your commit history
  • Create meaningful commit messages and review code before committing
  • Set up SSH keys for GitHub authentication to avoid repeated password entry
CodeWithHarry
2 hr 32 min video
3 min read
Git and GitHub Mastery: From Basics to Collaboration
You just saved 2 hr 29 min.
The big takeaway
A comprehensive 152-minute tutorial covering Git fundamentals (version control, commits, branches), GitHub essentials (repositories, pull requests, forking), GitHub Desktop GUI, VS Code integration, and multi-user workflows with real-world examples.
What is Git and Why It Exists
Git solves the collaboration problem
Git is a version control system created by Linus Torvalds in April 2005 to track who changed which line of code, when, and why. Before Git, developers working on Linux couldn't determine who made breaking changes, leading to constant conflicts and confusion.
April 2005
Git created in just a few days
Linus Torvalds developed Git to solve collaboration chaos
Centralized vs. Distributed version control
Centralized systems store all code on one server; if the server goes down or you lose internet, you cannot work. Distributed systems like Git give every developer a complete copy of the project history, allowing offline work and eliminating single points of failure.
Centralized
1 server (single point of failure)
Distributed (Git)
100 % redundancy (every dev has full copy)
Git's distributed model eliminates server dependency
Git is now ubiquitous
Approximately half of the world's software projects use Git today. It became so popular that Microsoft acquired GitHub for $8 billion in 2018.
~50%
of world's software projects use Git
Git's dominance in version control
Git vs. GitHub: Understanding the Difference
Git is the tool, GitHub is the platform
Git is software that tracks code changes locally on your computer. GitHub is an online platform (created in April 2008) where you host Git repositories remotely so others can access and collaborate on your code.
Git
1 local version control software
GitHub
1 remote repository hosting platform
Git manages code locally; GitHub hosts it online
GitHub Desktop simplifies Git workflows
GitHub Desktop is a GUI application that eliminates the need to memorize terminal commands. It makes Git accessible to non-technical users by providing a visual interface for commits, branches, and merges.
Git Installation and Setup
Installing Git on Windows, Mac, and Linux
On Windows, download from git-scm.com and run the installer. On Mac, use Homebrew (brew install git) after installing Homebrew. On Linux, use apt (apt-get install git). After installation, verify with 'git --version'.
1
Download Git from git-scm.com (Windows) or use Homebrew (Mac) or apt (Linux)
2
Run installer with default settings
3
Verify installation: git --version
4
Configure user identity: git config --global user.name and git config --global user.email
Git installation steps across platforms
Configure Git with your identity
Run 'git config --global user.name "Your Name"' and 'git config --global user.email "your@email.com"' so that every commit is attributed to you. This is essential for collaboration.
Core Git Concepts: The Four Locations
Code moves through four locations in Git
Working Directory (your local files) → Staging Area (files ready to commit) → Local Repository (committed snapshots on your machine) → Remote Repository (code on GitHub). You control this flow with git add, git commit, git push, and git pull.
1
Working Directory: Make changes to files
2
Staging Area: git add (select which files to commit)
3
Local Repository: git commit (save snapshot with message)
4
Remote Repository: git push (upload to GitHub)
Git's four-location workflow
The Big Four Git Commands
git init: Initialize a repository
Converts a folder into a Git repository by creating a hidden .git folder. This folder contains all version control data. Run 'git init' once per project.
git status: Check repository state
Shows which files are untracked, modified, or staged. Run it frequently to understand what Git sees. Output includes branch name, commits, and file status.
git add: Stage files for commit
Moves files from working directory to staging area. Use 'git add filename' for one file or 'git add .' to stage all changes. You can selectively stage only the files you want to commit.
git commit: Save a snapshot
Creates a checkpoint with a message describing changes. Use 'git commit -m "message"'. Good commit messages use present tense (e.g., 'Add login feature' not 'Added login feature').
Viewing Commit History
git log shows all commits
Displays full commit history with hash, author, date, and message. Use 'git log --oneline' to see commits in one line per entry, making it easier to scan history.
Branching: Working Independently
Branches allow parallel development
A branch is a pointer to a commit. Create a feature branch to work independently without affecting the main branch. If the feature fails, delete the branch; if it succeeds, merge it back.
1
Create branch: git branch feature-name
2
Switch to branch: git switch feature-name (or git checkout feature-name)
3
Make commits on the branch
4
Merge back: git merge feature-name (from main branch)
Typical branching workflow
Branching best practices
Create one branch per feature. Use descriptive names (e.g., 'feature/user-login'). Keep branches short-lived; merge as soon as work is complete. Delete merged branches. Never develop directly on main.
1
Create dedicated branch per feature
2
Use descriptive branch names
3
Keep branches short-lived
4
Delete after merging
5
Never develop on main
Best practices for branch management
Merging and Merge Conflicts
Merging combines branches
Use 'git merge branch-name' to integrate a feature branch into main. Git automatically combines changes if they don't conflict. A merge commit is created to record the merge.
Merge conflicts require manual resolution
Conflicts occur when the same file is edited differently in two branches. Git marks conflicting sections with <<<<<<, ======, and >>>>>>. You must manually choose which version to keep, then commit the resolution.
Stashing: Temporary Storage
Stash saves work without committing
Use 'git stash' to temporarily save uncommitted changes and clean your working directory. Retrieve them later with 'git stash pop'. Useful when you need to switch branches urgently without committing incomplete work.
1
Make changes to files
2
git stash (saves changes, cleans working directory)
3
Switch branches or handle emergency
4
git stash pop (restores stashed changes)
Stashing workflow for temporary storage
Rebasing: Keeping History Clean
Rebase replays commits on a new base
Instead of merging (which creates a merge commit), rebasing replays your branch's commits on top of the target branch. This keeps history linear and avoids merge commit clutter. Use 'git rebase main' from your feature branch.
When to merge vs. rebase
Use merge to preserve history and show that branches existed. Use rebase to keep history clean and linear. Many organizations prefer rebase to avoid merge commit bloat.
Tagging: Marking Releases
Tags mark important commits
Use tags to mark releases (e.g., v1.0, v1.1). Two types: annotated tags (with message) and lightweight tags (just a name). Create with 'git tag -a v1.0 -m "Release 1.0"' or 'git tag v1.0'.
Ignoring Files with .gitignore
Prevent tracking of unnecessary files
Create a .gitignore file and list files/folders to ignore (e.g., .env, node_modules/, build/). Git will not track these files. Essential for hiding secrets, build artifacts, and dependencies.
1
Create .gitignore file in repository root
2
Add patterns: .env, node_modules/, *.log
3
Use wildcards and directories with trailing slash
4
Commit .gitignore so team members use same rules
Using .gitignore to exclude files
Git doesn't track empty directories
To include an empty directory, add a .gitkeep file inside it. This allows Git to track the directory structure without actual content.
GitHub: Hosting and Collaboration
Create and manage repositories on GitHub
Sign up at github.com, create a new repository, choose public or private, optionally add README and .gitignore. Clone to your machine with 'git clone <url>' and start pushing code.
1
Sign up at github.com
2
Click 'New Repository'
3
Enter name, description, choose public/private
4
Add README and .gitignore if desired
5
Click 'Create Repository'
Creating a GitHub repository
Push and pull to sync with GitHub
Use 'git push origin main' to upload commits to GitHub. Use 'git pull origin main' to download changes from GitHub. 'git fetch' downloads without merging; 'git pull' downloads and merges.
Collaborate with pull requests
Create a pull request (PR) to propose merging a branch into main. Team members review, comment, and approve before merging. PRs enable code review and discussion before integration.
GitHub Desktop: GUI Alternative
GitHub Desktop eliminates command-line complexity
Download from desktop.github.com. Provides visual interface for cloning, committing, branching, and pushing. Ideal for beginners or those uncomfortable with terminal commands. Handles authentication automatically.
Workflow in GitHub Desktop
Clone repository → make changes → stage files (click +) → write commit message → commit to branch → publish branch → create pull request. All done through GUI without terminal.
VS Code Integration
Git features built into VS Code
VS Code has built-in Git support. Stage files, write commit messages, and push directly from the editor. Use the Source Control panel (Ctrl+Shift+G) to manage commits without terminal.
Git Graph extension visualizes history
Install 'Git Graph' extension in VS Code to see a visual representation of commits and branches. Helps understand project history and branch relationships at a glance.
Forking and Contributing
Fork creates a personal copy of someone else's repo
Click 'Fork' on GitHub to create your own copy of a repository. You have full control over your fork. Use forks to contribute to open-source projects or experiment without affecting the original.
Pull requests enable open-source contributions
After forking and making improvements, create a pull request to propose merging your changes into the original repository. Maintainers review and decide whether to accept. Only contribute meaningful changes.
Multi-User Workflows
Collaboration workflow: issues, branches, PRs
Create issues to assign tasks. Team members create branches for each issue. After completing work, they push and create pull requests. Maintainer reviews and merges. Issues are closed when merged.
1
Create issue describing task
2
Assign to team member
3
Team member creates feature branch
4
Commits and pushes changes
5
Creates pull request linked to issue
6
Maintainer reviews and merges
7
Issue closes automatically
Typical multi-user collaboration workflow
Handling merge conflicts in teams
When two team members edit the same file, conflicts arise. Communicate with teammates, resolve conflicts manually by choosing which changes to keep, then commit the resolution.
Git Best Practices
Write meaningful commit messages
Use present tense ('Add login feature' not 'Added login feature'). Be specific about what changed and why. Good messages help future developers understand history.
Never push secrets to GitHub
Never commit passwords, API keys, or database credentials. Use .env files and add them to .gitignore. If secrets are exposed, they can be exploited by attackers.
Review code before committing
Always check what you're about to commit. Use 'git status' and 'git diff' to review changes. Avoid committing unintended changes.
Keep branches short-lived
Merge feature branches into main as soon as work is complete. Long-lived branches cause integration problems and merge conflicts.
Future of Git: AI Integration
AI can generate commit messages
Tools like GitHub Copilot can automatically generate meaningful commit messages based on your code changes. This saves time and ensures consistency.
AI assists with code review and suggestions
AI can suggest improvements, catch bugs, and help with code generation. Pair programming with AI is becoming more common in modern development workflows.
Worth quoting
"Git is a distributed version control system that is fast, reliable, and very easy to use."
— CodeWithHarry, at [10:41]
"Never push secrets like passwords or API keys to GitHub. Use .env files and add them to .gitignore."
— CodeWithHarry, at [47:08]
"Write meaningful commit messages in present tense. Say 'Add login feature' not 'Added login feature'."
— CodeWithHarry, at [129:37]
Try this
Install Git on your machine (Windows/Mac/Linux) and verify with 'git --version'
Configure Git identity: git config --global user.name and git config --global user.email
Create a test repository locally using 'git init' and practice the four main commands (init, status, add, commit)
Create a GitHub account and push your test repository to GitHub
Practice branching: create a feature branch, make commits, and merge back to main
Create a .gitignore file and add files you want to exclude from tracking
Install GitHub Desktop and practice the same workflow through the GUI
Collaborate with a friend: fork their repository, make changes, and create a pull request
Practice resolving merge conflicts by editing the same file in two branches and merging
Install Git Graph extension in VS Code and visualize your commit history
Create meaningful commit messages and review code before committing
Set up SSH keys for GitHub authentication to avoid repeated password entry
Made with Glimpse by Wozart
glimpse.wozart.com/v/j00am4gx
Share this infographic

More like this