Git & GitHub

Remotes and GitHub

30 min

A remote is a copy of the repository somewhere else, usually GitHub. origin is the conventional name of the main one.

Connecting securely with SSH

ssh-keygen -t ed25519 -C "ada@example.com"
cat ~/.ssh/id_ed25519.pub        # copy this public key

Add the public key in GitHub under Settings → SSH and GPG keys, then test:

ssh -T git@github.com

Never share the private key (the file without .pub). Protect it with a passphrase.

Publishing a repository

git remote add origin git@github.com:ada/hello-git.git
git push -u origin main          # -u remembers the link for later pushes

Cloning an existing one:

git clone git@github.com:ada/hello-git.git

Staying in sync

Command Does
git fetch download new commits, change nothing locally
git pull fetch, then merge into your branch
git pull --rebase fetch, then rebase your local commits on top
git push upload your commits

If git push is rejected, someone pushed first. Run git pull --rebase, fix any conflicts, then push again. Never git push --force to a shared branch; if you must after rewriting your own branch, use git push --force-with-lease, which refuses when someone else's work would be lost.

Tracking branches

git branch -vv                   # which remote branch each local branch follows
git switch feature/x             # auto-tracks origin/feature/x if it exists
git push origin --delete old-branch

Releases and tags

git tag -a v1.2.0 -m "Contact form and rate limits"
git push origin v1.2.0

Tags mark exact versions you deployed, so you can always rebuild or roll back.

Check yourself

  • What is the difference between fetch and pull?
  • Your push is rejected. What do you do?
  • Why is --force-with-lease safer than --force?

Your progress is saved in this browser only.

Submit for review (10 points)