Remotes and cloning
Last updated
So far Kusina has lived in one folder on Ana's computer. To work with Joaquin, there needs to be a copy they can both reach. In this lesson you'll meet remotes (other copies of a repository that yours knows about), clone one, and read origin/main, a label that shows where the other copy was when you last looked.
By the end of this lesson you can
- Explain a remote as another copy of the repository, with a name and an address
- Copy a repository with git clone
- Explain remote-tracking branches such as origin/main, and when they change
Every copy is a whole repository
Git is distributed: every copy of a repository is complete. Ana's kusina has every commit; when Joaquin copies it, his has every commit too. Neither needs the other to read history, commit, or branch.
To work together, they need a copy they can both reach, usually on a hosting site such as GitHub, GitLab or Codeberg. The repositories you made in lessons 4.2 to 4.4 are such copies: Git repositories like Ana's, just without a working folder, on computers that are always on.
Remotes and origin
A remote is another copy of the repository that yours knows about: a short name for a long address.
git remote -vlists them, each with the address for fetching and for pushing (usually the same).- When you clone, Git names the copy you cloned from origin. It's only a name; it could be anything, but everyone uses origin.
git remote add <name> <address>adds one (lessons 4.8 and 5.5).
Addresses look like https://github.com/ana/kusina.git or [email protected]:ana/kusina.git (the second is SSH, lesson 4.8). The sandbox's pretend host is https://example.com/ana/kusina.git.
Clone Kusina
On GitHub, the address is under the green Code button:
- HTTPS and GitHub CLI. Two kinds of address. HTTPS works everywhere; the SSH address appears here too once you’ve added an SSH key (lesson 4.8). GitHub CLI shows a
gh repo clonecommand instead. - Address and copy button. The address to give
git clone, ending in.git. The button copies it. - Open in an app. Clone with GitHub Desktop, or open in GitHub’s Copilot app. Both run Git underneath; this course uses the terminal so it works the same everywhere.
- Download ZIP. Only the files, as they are now. No history and no Git: changes made to a ZIP can’t be pulled, committed or pushed.
git clone <address> [folder] makes a new folder, copies every commit into it, names the source origin, and checks out main. Clone is how Joaquin gets Kusina on his computer, and how you'll get any project you contribute to.
- See Kusina’s remote with
git remote -v - Go up to your home folder, and clone Kusina into a folder called
kusina-laptop - Go into it and check that it has origin too
- See its whole history with
git log --oneline
Working folder
no changes
Staging area
nothing staged
Repository
10 commits on main
Remote
origin: example.com/ana/kusina.git · in step, as of your last fetch
You are in ~/kusina. It is connected to a hosted copy, origin, and Joaquin has his own clone on his computer.
Your folders
- /home/ana
- kusina/(repository)◀ you are here
- README.md
- adobo.md
- build_index.py
- leche-flan.md
- lumpia.md
- pancit.md
- sinigang.md
- kusina/(repository)◀ you are here
The new folder has every commit and every file. It's a full repository in its own right.
origin/main
After cloning, your graph shows two labels on the newest commit: main and origin/main.
mainis your branch. It moves when you commit.origin/mainis a remote-tracking branch: Git's note of where origin's main was the last time you talked to origin. You can't commit on it. It only moves when yougit fetch,git pullorgit push.
$ git log --oneline --all -2 67e435d (HEAD -> main, origin/main) Cover the leche flan with foil ba04ca2 Add lumpiang shanghai recipe
67e435dHEAD →mainorigin/main Cover the leche flan with foilba04ca2Add lumpiang shanghai recipe98a5edcAdd a script that builds the index paged078487Make the sinigang steps clearer145dc1eAdd pancit bihon recipe52d1f4dSay how much salt goes in the adobo1c17fadAdd a README9c53888Add leche flan recipe1f359a2Add sinigang recipe601c654Add adobo recipe
git branch -a lists remote-tracking branches too, as remotes/origin/main.
Spot the trap: "origin/main is up to date"
Ana runs git status: “Your branch is up to date with ‘origin/main’.” She tells Joaquin she has all his work.
What happens if…
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- Pro Git: Working with Remotes: showing, adding and naming remotes
- Pro Git: Remote Branches: remote-tracking branches and when they move
- Git documentation: git-clone: what clone copies and sets up
- Git documentation: git-remote: -v, add, rename, remove