Skip to content
jsworkbench.
Learning path
Intermediate18 min

Remotes and collaboration

Understand the idea

A remote is another repository. push, fetch, and pull move labels between the two.

The idea

A is another repository known by a short name. is only the usual name. git clone their-slug creates your own repository whose origin points at theirs and whose commits start as a copy. git fetch updates origin's recorded heads. git pull fetches and then merges that head into your branch. git push moves their branch only when your commit contains their tip, unless you pass --force.

What changes

Fetch adds their commits to your object store and sets origin/main on the graph. Your stays put. Push, when you own the target, copies your commits into that repository and moves its label. If their label has commits you do not have, the push stops. --force moves it anyway and is the overwrite the undo lesson warned about. You can fetch a classmate's visible repository. You cannot push into it.

How the two repositories trade labels
CommandYour branchTheir branch
git fetch originUnmovedRecorded as origin/main
git pull origin mainMerges their tipUnmoved
git push origin mainUnmovedMoves, if the push is a fast-forward
git push --force origin mainUnmovedMoves even if commits are dropped

The command

On a repository you own twice, or on a clone, run git remote add origin their-slug, then git push origin main. Clone with git clone their-slug. The new repository is yours, origin tracks theirs, and the graph shows the copied commits. The command reference is the full set this terminal runs.

The mistake

Check your graph

After fetch, origin/main appears on their tip and your main label does not move. After a fast-forward push, their branch hash matches yours. A rejected push leaves both labels where they were.

Your repository

Add origin, push a branch, and clone a visible repository on this platform.

  1. Step 1

    Name the other repository

    origin is the usual name. practice is a second repository created for you when you run this, so you have somewhere to push.

  2. Step 2

    Make a commit the remote does not have

    In the editor, add this line to README.md: Ready to push

  3. Step 3

    Stage the new line

    origin does not have this edit until you commit and push.

  4. Step 4

    Commit it

    Your main is now ahead of origin.

  5. Step 5

    Push your branch

    This moves origin’s main to your commit, because the push is a fast-forward and you own that repository.

  6. Step 6

    Fetch without moving your branch

    Fetch records origin/main on the graph. Your own main label stays where it is.

The editor edits the working tree. Start a repository and the files appear here.

Follow the steps. Each command step can be placed in the terminal. Edit files in the editor, then stage them.
Supported command reference
  • init
  • add <path> | add .
  • commit -m "message" | commit --amend -m "message"
  • status
  • diff | diff --staged
  • log | log --oneline | log --graph | log --oneline --graph
  • show [ref]
  • branch | branch <name> | branch -d <name>
  • checkout <ref> | checkout -b <name> | switch <name> | switch -c <name>
  • merge <branch>
  • rebase <branch> | rebase -i <branch> | rebase --edit-todo <pick|drop|reword> <hash> [message] | rebase --continue | rebase --abort
  • cherry-pick <ref>
  • reset --soft <ref> | reset --mixed <ref> | reset --hard <ref>
  • revert <ref>
  • stash | stash list | stash pop | stash apply
  • restore <path> | restore --staged <path>
  • remote | remote add <name> <repo-slug>
  • clone <repo-slug> | git clone <repo-slug> | git fork <repo-slug>
  • fetch [remote] | pull [remote] [branch] | push [remote] [branch] | push --force [remote] [branch]
  • blame <path>
  • reflog
  • tag | tag <name> [ref] | tag -d <name>
  • bisect start | bisect good [ref] | bisect bad [ref] | bisect reset
  • config <key> <value> | config --list
  • write <path> <text> (workbench: edit the working tree)
  • issue new "title" | pr new <source> <target> "title" | review "comment" | review --request-changes "comment"

Commit graph

No commits yet. git init creates the first one.

Quiz

A quick check for understanding. Retry as often as you like; your learning path stays open.

01What does fetch change?
02Who can receive a push on this platform?

Ready to call this one understood?

Mark this lesson complete to earn 150 XP. You can always revisit it.

Sign in to save progress
Next lesson