GtGit · Lesson 5 of 8

Remotes: push, pull & GitHub

So far everything lived on your machine. A remote is a copy of your repository on a server — backup, publish point, and the way teams share work.

Bash
# Connect your repo to an empty GitHub repository:
git remote add origin https://github.com/you/my-project.git

# Upload your commits:
git push -u origin main
# (-u links the branches; afterwards plain 'git push' works)

# Download someone else's repository:
git clone https://github.com/them/cool-project.git

# Get new commits from the remote:
git pull

'origin' is just the conventional nickname for the remote you cloned from or first added. push sends your new commits up; pull brings new commits down and merges them into your branch. If you and a teammate both pushed, you must pull (and maybe resolve a conflict) before you can push.

The collaboration workflow on top of this is the pull request (PR): push your branch to the remote, open a PR proposing it be merged into main, teammates review and comment, then it's merged on the server. PRs are a GitHub/GitLab feature rather than a git one — but they're how virtually all team development works.

Bash
# Typical team flow:
git switch -c fix-header
# ...edit, add, commit...
git push -u origin fix-header
# Then open a Pull Request on GitHub from 'fix-header' into 'main'.

# After it's merged on GitHub:
git switch main
git pull
git branch -d fix-header