Working with Remotes
So far, everything has been local on your computer. Remotes let you sync your repository with servers like GitHub, GitLab, or Bitbucket.
Local vs Remote
| Local | Remote |
|---|---|
| On your computer | On a server (GitHub, etc.) |
| Only you can access | Others can access |
| Work offline | Needs internet |
| Your working copy | Backup + collaboration |
The Origin Remote
When you clone a repository or add a remote, it's typically called origin:
# Add a remote
git remote add origin https://github.com/you/repo.git
# View your remotes
git remote -v
Pushing Changes
To upload your commits to the remote:
git push origin main
This sends your local main branch commits to the origin remote.
Pulling Changes
To download changes from the remote:
git pull origin main
This fetches remote commits and merges them into your local branch.
Cloning a Repository
To create a local copy of a remote repository:
git clone https://github.com/someone/repo.git
This:
- Creates a new folder with the repo name
- Downloads all commits and branches
- Sets up
originautomatically - Checks out the default branch
The Push/Pull Workflow
Your Computer GitHub
┌─────────────┐ ┌─────────────┐
│ Local │ ───push───► │ Remote │
│ Repo │ ◄───pull──── │ Repo │
└─────────────┘ └─────────────┘
- Make changes locally
- Commit them
- Push to share with others
- Pull to get others' changes
Try It Out!
Use the remote simulator to practice pushing and pulling.
Visual Mode: Click "Push" and "Pull" buttons to sync Command Mode: Usegit push and git pull commands
Watch commits flow between your local repo and the remote!