PLAINFINCH learn by building

Remotes and GitHub

You will be able to connect your project to a GitHub repository and send your commits there for the first time.

What is a remote?

Your repository lives in a hidden .git folder inside the project. Every commit, branch and message is stored there, on your computer, and nowhere else. If the laptop dies, so does the bird club site's history. A remote is another copy of the same repository somewhere else, usually on a hosting service such as GitHub, GitLab or Codeberg, that you can send commits to and fetch commits from.

Inside your repository, a remote is only a name and an address. origin is the conventional name for the main one. It could be called github or backup instead; Git does not care. Most tools and tutorials assume origin, so use that unless you have a reason not to.

The practice terminal has no real network. GitHub is simulated: each address is an in-memory repository. The commands and the messages are the same ones you will see on a real machine.

git remote
git remote -v

How do you connect a project to GitHub?

First create an empty repository on GitHub using the New repository button. Leave the options for a README, a licence and a .gitignore unticked when you already have commits locally, because those options create a first commit on GitHub that your local history does not have, and your first push would be rejected.

GitHub then shows the address, something like https://github.com/you/bird-club.git. Back in the terminal, run git remote add origin followed by that address. Git prints nothing. Run git remote -v and you will see the address listed twice, for fetching and pushing. Adding a remote sends nothing over the network; it only saves the bookmark.

git remote add origin https://github.com/you/bird-club.git
git remote -v

What does git push -u origin main do?

git push origin main means: send my main branch, and every commit it needs, to the remote called origin, and update the main branch there. The first time, GitHub has no main yet, so Git prints * [new branch] main -> main.

The -u flag (long form --set-upstream) also records that your local main tracks origin/main. After that, a bare git push or git pull on main knows where to go, and git status tells you whether you are ahead or behind. You only need -u once per branch.

Watch the Graph view. A dashed origin/main label appears on the same dot as main. That label is your repository's memory of where main was on the remote the last time you talked to it.

git remote add origin https://github.com/you/bird-club.git
git push -u origin main
git status
git log --oneline --all
FigureTwo repositories with the same three commits: the bird-club repository on your computer, with main and a dashed origin/main label, and GitHub's origin at github.com/you/bird-club.git with main. git push -u origin main sends commits across.Two repositories with the same three commits: the bird-club repository on your computer, with main and a dashed origin/main label, and GitHub's origin at github.com/you/bird-club.git with main. git push -u origin main sends commits across.
After git push -u origin main, both copies hold the same commits. The dashed origin/main label is only your repository's memory of GitHub, updated when you push, fetch or pull.

What is origin/main, and why can it be out of date?

origin/main is a remote-tracking branch. You never commit on it. Git moves it when you push, fetch or pull. Between those moments it does not change, even if a club member pushes a new sighting to GitHub. It reflects what you last heard, which may be an hour old.

That is why git status can say Your branch is up to date with 'origin/main' while GitHub has newer commits. The message compares you with your last snapshot of the remote. Run git fetch first if you want a current answer. The next lesson covers fetch and pull properly.

What if the address is wrong?

Typos in the address are common, and so is a repository that was renamed on GitHub. Fix the address with git remote set-url origin and the right address; there is no need to remove and add the remote again. Check with git remote -v afterwards.

To remove a remote entirely, use git remote remove origin. That deletes only the bookmark and the origin/ labels in your repository. It never touches the repository on GitHub, and your local commits stay exactly where they were.

You can also have more than one remote. Someone who copies (forks) the bird club site on GitHub often keeps origin for their own copy and adds upstream for the club's original, so they can fetch the club's new commits.

git remote add origin https://github.com/you/bird-clb.git
git remote set-url origin https://github.com/you/bird-club.git
git remote -v

How does git clone fit in?

git remote add is for a project that started on your computer. When the project already exists on GitHub, you use git clone with its address instead. Clone creates a new folder, downloads every commit, checks out main, adds origin pointing back to the address, and sets the upstream for you. A fresh clone is ready for git pull and git push straight away.

Clone makes a full copy, including all history. That surprises people who expect a download of the current files only. It also means that anything ever committed to the repository, including a secret someone removed later, arrives with the clone. The practice folder here is already a repository, so cloning into it would fail; the push and pull lesson starts from a cloned bike shop repository instead.

What about logging in to GitHub?

Real pushes need proof that you are allowed to write to the repository. GitHub stopped accepting account passwords for Git over HTTPS in 2021. You either sign in through a credential helper (GitHub Desktop, the gh auth login command, or Git Credential Manager, which opens a browser), use a personal access token, or use SSH keys with an address that starts [email protected]:.

If a push fails with Authentication failed or Permission denied, the remote setup is usually fine and the login is the problem. Fix the login and push again; there is no need to change the remote. The practice terminal skips logging in entirely.

What should you check when an AI tool gives you remote commands?

Assistants usually produce a block of commands such as git init, git add ., git commit, git branch -M main, git remote add origin and git push -u origin main. Read the address in the remote add line before running it; models invent plausible user and repository names. If origin already exists, remote add fails with remote origin already exists, and the fix is set-url, not deleting the .git folder.

Also check that git add . is not about to include files you would not want online, such as .env files with keys. A .gitignore belongs before the first push. The secrets lesson covers this in detail.

Field notes

  • A remote is a named address for another copy of your repository, usually called origin.
  • git remote add origin <url> connects a project that started on your computer.
  • git push -u origin main sends main and remembers where later pushes should go.
  • git remote -v shows the address, and git remote set-url fixes a wrong one.

Easy to get wrong

The README becomes a first commit on GitHub that your local repository lacks, so your first push is rejected until you pull and merge it.

Deleting .git throws away your whole history to fix a one-line setting.

Adding a remote only saves a name and an address. Nothing moves until you push.

Questions people ask

Do I have to call it origin?

No, any name works. origin is the convention, and many commands and guides assume it, so stick with it unless you have several remotes.

Is GitHub the same thing as Git?

No. Git is the version control tool on your computer. GitHub is a website that hosts Git repositories and adds features such as pull requests and issues. GitLab, Bitbucket and Codeberg do similar jobs.

Do I need -u every time I push?

Only on the first push of each branch. After the upstream is set, git push on that branch is enough.

Can a remote be a folder on my own computer or a USB drive?

Yes. Real Git accepts a folder path as a remote address. It is a cheap backup, but it does not protect you from losing the computer or the drive.

Keep going