Remote repositories: clone, push, pull
Theory
Machine translation, not yet reviewed by a native speaker.
Until now everything has been local. A remote repository (remote) is a copy of the project on a server: GitHub, GitLab or your own VPS. You work together through it.
git clone git@github.com:IGD-Uchiha/Website-IGD-Games.git # download the whole project, with its history
git remote -v # which remotes the repository is linked to; the main one is called origin
git push # send your commits
git push -u origin feature # the first push of a new branch (-u remembers the link)
git pull # get other people's commits and merge them into the current branch
git fetch # only download, merge nothing — to see what has changed
git pull = git fetch + git merge. If someone changed the same lines, pull can produce a conflict, and you resolve it the same way you did in the lesson about conflicts.
How to connect: HTTPS or SSH.
- HTTPS (
https://github.com/…) — you need an access token instead of a password; - SSH (
git@github.com:…) — with a key:ssh-keygen -t ed25519, and the public key (~/.ssh/id_ed25519.pub) is added on GitHub under Settings → SSH keys. Never give the private key to anyone.
The team rule: before starting work — git pull; after finishing a piece — commit and push. That keeps conflicts small.
git push rejected with the message rejected … fetch first? That means the server has commits you don't have. Run git pull, resolve any conflicts, and push again. Never use git push --force on shared branches: it wipes out other people's work.