5. Remote Repositories & GitHub
Remote Repositories & GitHub
Your local repository exists only on your machine. A remote repository is a copy of your repository stored on a server (like GitHub). Pushing to a remote serves two purposes: backup (your code survives if your laptop dies) and collaboration (your team can access and contribute to the code).
🔗 Connecting to a Remote
After creating a repo on GitHub, connect your local repo. origin is the conventional name for your primary remote. You can name it anything, but origin is the universal convention.
Verify the remote was added correctly:
⬆️ Push — Sending Your Commits to GitHub
Push your main branch to origin for the first time. The -u flag sets 'origin main' as the default upstream:
After the first push, you can just use:
Push a feature branch to remote (so teammates can see it):
⬇️ Pull — Getting Updates from GitHub
Clone a repository from GitHub to your local machine:
Get the latest changes from the remote (teammates' commits). pull = fetch + merge in one step. It downloads the remote changes AND merges them into your current branch:
Alternatively, fetch without merging (inspect before applying). This lets you check what is on the remote before you merge:
🔄 The Daily Collaboration Workflow
In a team using Git, the daily workflow follows this pattern — every single day, before starting work:
- Make sure you're on main:git checkout main
- Pull the latest changes your teammates pushed yesterday:git pull
- Create your branch for today's work:git checkout -b feature/todays-feature
- Do your work...
- Stage and commit frequently (every logical unit of work):git add . git commit -m "feat: add password validation to signup form"
- Push your branch to GitHub:git push -u origin feature/todays-feature
- Open a Pull Request on GitHub: This is where code review happens before merging to main.
⬇️ Pulls — What Actually Happens Under the Hood
git pull is shorthand for two commands run back-to-back:
Understanding the two-step nature helps you diagnose pull failures:
Use when you want to inspect remote changes before merging. Safe — nothing in your workspace changes.
Use in daily workflow when you trust the remote and just want the latest code in your branch.
git pull --rebase replays your local commits on top of the remote changes instead of creating a merge commit — keeps history linear.
Knowledge Check
Ready to test your understanding of 5. Remote Repositories & GitHub?