🚀 Introduction
Git and GitHub are essential tools for developers, enabling version control and collaboration on projects. Whether you’re a beginner or an experienced programmer, mastering Git is a must.
This crash course will cover:
✅ What is Git & GitHub?
✅ Basic Git Commands
✅ Working with GitHub
✅ Collaboration & Best Practices
🔹 What is Git & GitHub?
Git
- A distributed version control system that tracks changes in your code.
- Allows you to revert to previous versions, branch code, and merge changes.
GitHub
- A cloud-based platform that hosts Git repositories.
- Enables team collaboration, open-source contributions, and project management.
🔹 Installing Git
- Download Git from git-scm.com.
- Verify Installation:
git --version
🔹 Basic Git Commands
1. Initialize a Git Repository
git init
- Creates a
.git
folder to track changes.
2. Check File Status
git status
- Shows untracked, modified, or staged files.
3. Stage Changes
git add <filename> # Add a specific file
git add . # Add all files
4. Commit Changes
git commit -m "Your commit message"
- Saves changes with a descriptive message.
5. View Commit History
git log
🔹 Working with GitHub
1. Create a GitHub Account
- Sign up at github.com.
2. Link Git to GitHub
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
3. Create a Remote Repository
- Click “New” on GitHub and follow the steps.
4. Connect Local Repo to GitHub
git remote add origin https://github.com/yourusername/repo.git
5. Push Code to GitHub
git push -u origin main
🔹 Branching & Merging
1. Create a New Branch
git branch feature-branch
git checkout feature-branch
(or use git checkout -b feature-branch
to create & switch)
2. Merge a Branch
git checkout main
git merge feature-branch
3. Resolve Merge Conflicts
- Open conflicting files, edit, then:
git add .
git commit -m "Fixed merge conflict"
🔹 Collaboration on GitHub
1. Cloning a Repository
git clone https://github.com/user/repo.git
2. Pulling Latest Changes
git pull origin main
3. Forking & Pull Requests (PRs)
- Fork a repo on GitHub.
- Make changes, then create a PR for review.
🔹 Best Practices
✔ Commit Often – Small, frequent commits are better than huge ones.
✔ Write Clear Messages – Example: "Fix login bug"
instead of "Updated code"
.
✔ Use .gitignore
– Exclude files like node_modules/
, .env
, etc.
✔ Review Before Merging – Always test changes before merging into main
.
🎉 Conclusion
You now know the basics of Git & GitHub! To recap:
- Git tracks code changes locally.
- GitHub hosts repositories online for collaboration.
- Branching, merging, and pull requests help teams work efficiently.
📌 Next Steps
- Practice by contributing to open-source projects.
- Explore GitHub Actions for CI/CD.
- Learn advanced Git commands (
rebase
,stash
,cherry-pick
).
💬 Got questions? Drop them in the comments!