Remotes & clone
Your repo, their repo, and the sticky notes that remember where they were.
1 Learn the idea
So far everything lived on your laptop. Teams share work through a remote: another full copy of the repository, usually on GitHub or GitLab. By convention the one you cloned from is called origin.
Three different "mains"
mainon origin: the real branch on the server. Your teammates move it.origin/mainon your laptop: your memory of where origin's main was at the lastfetch,pullorpush.mainon your laptop: your own branch. Only you move it.
2 Watch it happen
Press Play or use → to step through. Watch the graph as each command runs.
Read this demo as text
$ git clone git@github.com:you/project.git
Cloning copies every commit from origin and creates your own
main, plus the bookmarkorigin/mainpointing at the same commit.$ git remote -v
git remote -vlists the remotes this repo knows about. There is one:origin, used for both fetching and pushing.$ git branch -a
-ashows local branches and remote-tracking ones (listed asremotes/origin/main). They are separate things.$ teammate push -m "Add checkout page"
Your teammate Sam pushes a commit to origin. Look at the top panel: origin's
mainmoved. Your laptop has no idea yet.$ git status
Status says "up to date with origin/main"… because it compares with your last postcard. Git does not check the network by itself.
$ git fetch
git fetchcontacts origin, downloads Sam's commit and movesorigin/mainforward. Yourmainand your files stay exactly where they were.$ git status
Now status knows: your branch is behind
origin/mainby 1 commit and can be fast-forwarded.$ git merge origin/main
Merging the bookmark into
mainbrings you up to date. Since you had nothing new, it is a simple fast-forward. (Fetch + merge is exactly whatgit pulldoes, next lesson.)$ git branch -vv
-vvshows each branch with its upstream (the remote branch it tracks) and whether it is ahead or behind.
- Downloads new commits
- Moves origin/* bookmarks
- Never changes your branches or files
- Safe to run anytime
- Runs fetch first
- Then merges (or rebases) into your branch
- Changes your branch and files
- Can produce conflicts
git clone <url>Copy a remote repository to your machinegit remote -vList remotes and their URLsgit fetchDownload new commits and update origin/* (safe)git branch -vvShow branches with upstream and ahead/behind3 Check your understanding
What is origin/main on your laptop?
A teammate pushed 3 minutes ago. You run git status and it says "up to date with origin/main". Why?
Look at the graph. How many commits is your main ahead of origin/main?
Which command can never change your working files?
4 Practice for real
Catch up with the team
Sam pushed two commits to origin while you were away. Bring your local main up to date with origin without creating any new commit of your own.