A remote is a repository hosted elsewhere — usually on GitHub — that a local repository stays connected to.
git clone https://github.com/username/repo-name.git
cd repo-name
# A complete copy, full history included, ready to work onFor a project that started with git init locally, rather than a clone — create an empty repository on GitHub first, then connect it.
git remote add origin https://github.com/username/repo-name.git
git branch -M main
git push -u origin mainorigin is the conventional name for a repository's primary remote — not a special keyword, just the default everyone uses.
git push
# Sends commits on the current branch to the remote
# First push of a new branch needs -u (short for --set-upstream)
# to link the local and remote branch together, once:
git push -u origin feature-login
# Every push after that, on that branch, can just be: git pushgit pull
# Downloads new commits from the remote and merges them into the current branch
# Equivalent to: git fetch, then git mergeDownloads what changed on the remote without touching local files — useful for seeing what's new before deciding whether to merge it in.
git fetch
git log origin/main # see what's new on the remote before pulling it ingit remote -v
# origin https://github.com/username/repo-name.git (fetch)
# origin https://github.com/username/repo-name.git (push)| Command | Direction |
|---|---|
| git clone | Remote -> new local copy |
| git push | Local -> remote |
| git pull / git fetch | Remote -> local |