Remotes — push and pull
A remote is another Git repo, usually on a server. `push` uploads your commits, `pull` downloads theirs. `origin` is the conventional name of the main remote.
Remotes are stored in .git/config under [remote "<name>"] with a URL and a fetch refspec (+refs/heads/*:refs/remotes/<name>/*). Listing: git remote -v. Adding: git remote add <name> <url>. URLs can be HTTPS, SSH, or local paths.
Fetch vs pull: git fetch updates refs/remotes/origin/* — the local cache of remote branches — without touching your working tree or current branch. git pull is fetch + a merge or rebase of origin/<current-branch> into your current branch. Always safe to fetch; pull mutates your branch.
Tracking branches: a local branch's upstream is stored in .git/config as branch.<name>.remote and branch.<name>.merge. Set with -u on first push or git branch --set-upstream-to=origin/<name>. Once set, git status shows ahead/behind, git pull/push need no args.
Push refspecs: git push origin local:remote pushes a local branch to a different remote name. git push origin :branch-to-delete (legacy) or git push origin --delete branch-to-delete (modern) removes a remote branch.
Force-push safety: git push --force overwrites the remote ref unconditionally — dangerous if someone pushed in between. git push --force-with-lease only force-pushes if the remote is at the SHA you last fetched, preventing accidental overwrites of others' commits. Always prefer --force-with-lease.
HTTPS vs SSH: HTTPS uses a personal access token (PAT) for auth — must be configured in a credential helper. SSH uses a key pair (~/.ssh/id_ed25519 typically) added to the host's account. SSH is friendlier for daily use; HTTPS works behind firewalls that block 22.
Practice
First push of branch `feature/login` to `origin`, with tracking set up.
Practice
Delete the remote branch `feature/old` from `origin`.
Practice
Complete the safe force-push command:
git push origin feature/cleanup
Grounded on https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
Next up
Pull Requests on GitHub
A PR is a proposal to merge your branch into another. GitHub shows the diff, runs CI, and lets reviewers comment line-by-line before approving.