Remote repositories
Everything so far lived on your machine. Now connect to a repository on the internet and learn to push, fetch, and pull without surprises.
What you'll learn
- You can connect a remote and push your commits
- You can explain the difference between fetch and pull
- You understand tracking branches and the `-u` option
A remote is the same repository living somewhere on the internet, usually on GitHub, and by convention it's named origin. You connect it with git remote add origin <URL>, send your commits up with git push, and bring other people's down with git pull. Nothing about your local workflow changes — the remote is just another copy that everyone agrees to meet at.
Knowing the difference between git fetch and git pull separates the confident from the anxious. fetch only downloads the remote's latest state and leaves your branch alone. pull fetches and immediately merges into your branch. When you want to see what landed before accepting it, fetch first, read git log origin/main, then merge.
The -u in git push -u origin main pairs your local branch with the remote one. Once paired, plain git push and git pull are enough from then on. And making git pull --rebase your default keeps meaningless "Merge branch 'main'…" commits out of the history — your commits get replayed on top of what came in, so the log stays a straight line.
Commands for this step
Don't just read them — type them into a real terminal. Your hands have to remember, not your eyes.
git remote add origin <URL>- Connect this repository to a remote and name it `origin`.
git push -u origin main- Push and pair the branches. After this, plain `git push` works.
git fetch origin- Download the remote's latest state without touching your branch.
git pull --rebase- Pull and replay your commits on top, keeping history in a straight line.