Code of the Day
BeginnerGit & Version Control

Working with remotes

clone, push, pull, fetch — sync your repository with a server like GitHub.

FundamentalsBeginner9 min read
Recommended first
By the end of this lesson you will be able to:
  • Explain what a remote is and how local and remote history relate
  • Clone, push, and pull a repository
  • Distinguish fetch from pull

So far everything has lived on your machine. A is a copy of your repository hosted elsewhere — usually a service like GitHub — that you sync with. Remotes give you a backup, a place to collaborate, and the thing deploys from. Crucially, git is distributed: your local repo is complete on its own, and you sync with the remote deliberately.

Getting a repository: clone

To start from an existing remote repo, clone it — this downloads the full history and sets up the link automatically:

git clone https://github.com/user/project.git
cd project

The remote is now known to your repo as origin (the default name).

Sending and receiving changes

Two everyday commands keep local and remote in sync:

git push        # send your local commits up to the remote
git pull        # bring the remote's new commits down and merge them in

The first time you push a new branch, set its upstream so future pushes are just git push:

git push -u origin add-login

fetch vs pull

These are often confused:

  • git fetch downloads the remote's new commits but does not change your working files. It just updates your knowledge of the remote.
  • git pull is fetch plus merge — it downloads and integrates the changes into your current branch.

fetch is the cautious move: look at what changed (git log origin/main) before deciding to merge. pull is the convenient one when you're ready to take the changes.

Do it yourself: create an empty repo on GitHub, then from your local project run the git remote add origin … and git push -u origin main lines it shows you. Refresh the page — your commits are there. You've done the full local-to-remote round trip by hand.

When the agent's away

Cloning, branching, committing, and pushing are the entire day-to-day loop of shipping code. With just these commands you can pull down a project, make a change on a branch, and push it for review — no assistant required. That independence is the whole point of this module.

Where to go next

You've completed the beginner Git module — you can manage the full local-and- remote workflow yourself. The intermediate Git in practice module goes deeper: merging vs rebasing, resolving conflicts by hand, and undoing anything.

Finished reading? Mark it complete to track your progress.

On this page