git

🏠 Homepage

⬅️ Previous: πŸ”„ Basic Git Workflow

7. πŸ“‚ Understanding Repositories: Local vs Remote

When working with Git and GitHub, it’s important to understand the difference between local and remote repositories.


πŸ–₯️ Local Repository

A local repository exists on your own computer. It is where you:

βœ… Example:

git init my-project
cd my-project
touch index.html
git add .
git commit -m "Initial commit"

Now you have a Git repository only on your computer.


🌐 Remote Repository

A remote repository is hosted on a server like GitHub. It’s used to:

You can connect your local repo to GitHub: βœ… Example:

git remote add origin git@github.com:username/my-project.git
git push -u origin main

This pushes your local changes to the remote GitHub repository.

πŸ” Common Git Commands

Action Command
Clone repo git clone <repo-url>
Add remote git remote add origin <repo-url>
Push changes git push origin main
Pull updates git pull origin main

🎯 Summary

Feature Local Repository Remote Repository
Location On your device On a server (e.g., GitHub)
Access Only you Anyone with permission
Purpose Write & test code Share & collaborate

πŸ’‘ Tip: Always commit locally first, then push to remote to save and share your work.

➑️Up Next: πŸ” Setting up SSH Keys