Git and GitHub Tutorial β The Complete Beginner to Advanced Guide
Introduction to Git and GitHub
What is Git?
Git is a free, open-source distributed version control system developed by Linus Torvalds in 2005. It’s widely used to track changes in code and collaborate on software projects.
Why Git Was Created
Git was designed to efficiently and securely manage contributions to large codebases (e.g., the Linux kernel) in a decentralized way.
Key Features
- Distributed system
- Fast performance
- Branching and merging
- Data integrity with SHA-1
- Offline support
What is GitHub?
GitHub is a cloud-based platform built on top of Git, offering additional collaboration tools like pull requests, issue tracking, project boards, and CI/CD workflows.
Git vs GitHub β Key Differences
| Feature | Git | GitHub |
|---|---|---|
| Type | Version Control System (VCS) | Repository Hosting Platform |
| Mode | Local + CLI | Web UI + Remote Collaboration |
| Tools | Core VCS Commands | Pull Requests, Issues, Teams |
GitHub Features
- Repositories & project hosting
- Pull requests for collaboration
- GitHub Actions (CI/CD)
- Issues, wikis, and team management
Installing Git
Windows
- Download from git-scm.com
- Run the installer and follow defaults
- Verify:
git --version
macOS
brew install git
Or:
xcode-select --install
Linux (Debian/Ubuntu)
sudo apt update
sudo apt install git
Basic Git Configuration
Set Username & Email
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check Config
git config --list
Git Basics
Creating a Repository
git init
Git Workflow Overview
- Working Directory β where files are edited
- Staging Area β add files using
git add - Repository β commit changes with
git commit
Staging & Committing
git add filename
git commit -m "Initial commit"
Viewing Commit History
git log
Working with Branches
What is a Branch?
A branch allows parallel development without affecting the main codebase.
Create & Switch Branch
git checkout -b feature-login
Merge Branch
git checkout main
git merge feature-login
Delete Branch
git branch -d feature-login
Remote Repositories
Clone a Repo
git clone https://github.com/user/repo.git
Add a Remote
git remote add origin https://github.com/user/repo.git
Push Changes
git push -u origin main
Pull Changes
git pull origin main
GitHub Essentials
Create GitHub Account
Sign up at github.com
Create New Repository
- Click New
- Name your repo
- Choose visibility (public/private)
Push Local Repo
git remote add origin https://github.com/username/repo.git
git push -u origin main
Fork & Star Repositories
- Star: Bookmark useful projects
- Fork: Create your own copy
Collaborating with Others
Pull Requests
Propose changes to a repo.
Reviewing & Merging PRs
- View code changes
- Add comments
- Click Merge pull request
Resolve Merge Conflicts
Edit the conflict areas, then:
git add .
git commit
Git Ignore & .gitignore
What is .gitignore?
A file that tells Git to ignore specific files/folders.
Example Entries
node_modules/
.env
*.log
Git Tags & Releases
Create Tag
git tag v1.0
Annotated vs Lightweight
- Annotated: Includes metadata
- Lightweight: Just a reference
Push Tag to GitHub
git push origin v1.0
Undoing Changes
Git Reset
git reset --hard HEAD~1
Git Revert
git revert <commit-id>
Git Checkout (Restore File)
git checkout -- filename.txt
GitHub Actions (Intro)
What Are GitHub Actions?
CI/CD automation built into GitHub.
Example Workflow
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: echo "Hello GitHub Actions!"
Best Practices
Commit Message Guidelines
- Use imperative mood:
Add,Fix,Update - Keep it short and meaningful
Branch Naming Conventions
feature/login-formbugfix/navbar-glitch
Git GUI Clients
GitHub Desktop
Beginner-friendly Git client by GitHub.
SourceTree
Powerful GUI by Atlassian for Git & Mercurial.
π GitKraken
Modern Git client with a beautiful interface.
Final Thoughts
Git and GitHub empower developers to collaborate, version-control, and ship quality code faster. Whether you’re building solo or as a team, mastering these tools is essential in todayβs development world.
Practice. Collaborate. Push code. Repeat.
Share Now :
