π§ 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-form
bugfix/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 :