Remotes — GitHub and GitLab
So far the bakery's history lives only on your laptop. If the laptop dies, the history dies with it, and your friend who helps with the CSS cannot see any of it. A remote is a copy of the repository on another computer, and services like GitHub and GitLab host those copies for teams and individuals.
The rule
Your laptop and the remote are two copies; push and pull keep them in step.
Git is distributed: every clone holds the full history. A hosting service is simply one copy that everyone agrees to share. GitHub and GitLab both host Git repositories and add features around them: a web view of the code, issue tracking, code review, and automated checks. GitLab can also be installed on a company's own servers.
Connecting a remote. Create an empty repository on the service, then:
git remote add origin https://github.com/crumb-bakery/site.git
git push -u origin mainoriginis the conventional nickname for the main remote.pushuploads your new commits.-uremembers that yourmaingoes withorigin'smain, so later you can just typegit push.
Joining an existing project. Your friend copies the whole repository, history included:
git clone https://github.com/crumb-bakery/site.gitCloning sets up origin automatically.
Getting other people's work.
git fetchdownloads new commits from the remote but does not touch your files or your branches. It updatesorigin/main, Git's local record of where the remote'smainis.git pullis a fetch followed by combining the remote's changes into your current branch (a merge by default, or a rebase if configured).
When a push is refused. If someone else pushed first, the remote has commits you do not. Git refuses your push rather than lose their work. Pull first, resolve any conflicts, then push again.
Hosting services also handle who may do what. A repository can be public or private, and collaborators get read or write access. Signing in from the command line usually uses an SSH key or a personal access token rather than your account password.