The Two Worlds of Git
Git is distributed, meaning you have a full copy of the project on your machine, and there's usually a central copy on the internet (GitHub).
Local Repo
- ✅ Lives on your computer
- ✅ Works offline
- ✅ Instant operations
- 🔒 Private to you
Remote Repo
- ✅ Lives on GitHub/GitLab
- ✅ Needs internet
- ✅ Backup of your code
- 🌍 Public/Shared
Connecting Them
To link your local folder to a GitHub repository, we use "remotes".
# Add a remote named "origin"
git remote add origin https://github.com/user/repo.git
# Verify it worked
git remote -vNote: "origin" is just a nickname for the URL. You could call it anything, but "origin" is the standard convention.
Syncing Commands
git clone [url]
Downloads an entire repository from the internet to your computer. Creates the folder for you.
git clone https://github.com/facebook/react.gitgit push
Uploads your committed changes to the remote repository.
git push origin maingit pull
Downloads new changes from the remote and merges them into your local files.
git pull origin mainThe Full Cycle
You
git push
git pull
GitHub
Check Your Understanding
1. What is the main purpose of 'git init'?
✓To initialize a new Git repository
To download a repository from GitHub
To install Git on your computer
To login to GitHub
2. Which command sets your user name?
git name user 'Name'
✓git config --global user.name 'Name'
git setup user 'Name'
git init user 'Name'