About this chapter
So far your work has lived only on your own machine. In this chapter you'll connect your repository to a remote on GitHub so your commits are backed up, visible online, and ready to share with others.
You'll clone an existing repository, add a remote to a project you started locally, push your commits, and bring down other people's work with fetch and pull. The last lesson covers the two ways to authenticate with GitHub - HTTPS with a token, and SSH keys - so pushing and pulling just works.
Lessons from courses
- 1 What is a remote? Understand what a Git remote is - a copy of your repo hosted on GitHub - why it's named origin, and how to list remotes with git remote -v.
- 2 Cloning a repository How git clone works: copy a GitHub repository to your machine with full history, a working copy, and origin set up so push and pull just work.
- 3 Adding a remote Started a repo with git init? Create an empty GitHub repo and connect it with git remote add origin so your local commits have somewhere to push.
- 4 Pushing changes What git push does, how git push -u origin main sets the upstream branch, and why every push after that is just a plain git push on its own.
- 5 Fetching and pulling The difference between git fetch and git pull: fetch downloads new commits without touching your files; pull fetches and merges them into your branch.
- 6 HTTPS vs SSH authentication Git HTTPS vs SSH for GitHub: authenticate with a personal access token over HTTPS or SSH keys from ssh-keygen. See the difference and which to pick.
- 7 Git submodules Git submodules explained: add another repository inside yours, clone a project with submodules, update them, and avoid the empty-folder trap.