Git is a version control system — it helps you save, track, and manage changes in your code.
GitHub is a cloud service where you can upload your Git projects and collaborate with others.
Let's learn the basics!
📦 Step 1: Install Git
- Download Git: git-scm.com
- Install it with default settings.
🗂️ Step 2: Basic Git Commands
Command | What it does | Example |
---|---|---|
git init |
Start a new Git project in your folder. | git init |
git clone |
Copy a project from GitHub to your computer. | git clone https://github.com/user/repo.git |
git add |
Stage (save) files to be committed. |
git add . (add all files) |
git commit |
Save a snapshot of your staged files. | git commit -m "Your message" |
git status |
Check the status of your project. | git status |
git push |
Send your code to GitHub. | git push origin main |
git pull |
Get the latest changes from GitHub. | git pull origin main |
git remote |
Manage connections to GitHub repositories. | git remote add origin URL |
git branch |
List or create branches. |
git branch / git branch new-branch
|
git checkout |
Switch between branches. | git checkout branch-name |
git diff |
See the changes you made compared to the last commit. | git diff |
git merge |
Merge changes from one branch into another. | git merge branch-name |
cd .. |
Move up one folder in your terminal. | cd .. |
🚀 Step 3: Common Git Workflow
Here’s a typical workflow you might follow:
- Clone the project (if it already exists):
git clone https://github.com/username/project.git
cd project
- Create a new project (if starting fresh):
mkdir project
cd project
git init
Make some changes (edit files, create code).
See what changed:
git status
- Stage the changes:
git add .
- Commit the changes:
git commit -m "Initial commit"
-
Push the code to GitHub:
- First, connect your GitHub repository:
git remote add origin https://github.com/username/project.git
-
Then push:
git push origin main
-
Working with branches:
- Create a new branch:
git branch new-feature
-
Switch to it:
git checkout new-feature
-
Merge it later:
git checkout main git merge new-feature
- Pull latest changes from GitHub:
git pull origin main
-
See differences:
git diff
🎯 Important Notes
- git init is for new projects.
- git clone is for existing projects.
- Always use git add and git commit to save changes locally.
- Use git push to upload your commits to GitHub.
- Use git pull to download new changes from GitHub.
- Branches help you work on new features without messing up your main project.
✨ Bonus Tip
🔒 Always commit meaningful messages like:
git commit -m "Add login form UI"
instead of:
git commit -m "stuff"
Would you also like me to create a cheat sheet image 📄 you can save for quick reference?
Let me know! 🚀