thecodingidiot.com

Version ControlRemotes

Remotes

Everything so far has been local. Your commits exist only on your machine — if the disk fails, they are gone. A remote is a second copy of the repository living somewhere else. It is your backup, and it is how you share work with other people.

The remote does not have to be GitHub. It can be any server you can reach over SSH, or another directory on the same machine. GitHub is the most common choice because it is free for public repositories and provides a web interface for reading history and reviewing changes.

The first remote you add to a repository is conventionally named origin. That name has no special meaning in git — it is a shorthand you can rename or remove.


Create a repository on GitHub

Log in to GitHub, click New repository, name it f02-practice, set it to Public, and click Create repository. Do not initialise it with a README or a .gitignore — your local repository already has those.

Copy the SSH clone URL from the Quick setup section at the top of the page: [email protected]:<username>/f02-practice.git

If you have the GitHub CLI (gh) installed (see cli.github.com) you can do this from the terminal instead:

gh repo create f02-practice --public --source=. --remote=origin

That creates the remote repository and adds it as origin in one step. If you used the gh CLI, origin is already configured — skip to Push. If you used the web UI, continue with the next section.


Connect your local repository

Inside your f02-practice directory:

git remote add origin [email protected]:<username>/f02-practice.git

Verify:

git remote -v

You should see origin listed twice — once for fetch and once for push.


Push

git push -u origin main

The -u flag sets the upstream tracking reference: git now knows that your local main corresponds to origin/main. After this, git push and git pull with no arguments know where to go.

Refresh the GitHub page — your commits and files are there.


Fetch and pull

Git never automatically downloads remote changes. You ask for them explicitly.

git fetch downloads everything the remote has that you do not, without changing your working tree or current branch:

git fetch origin

After fetching you can compare:

git log HEAD..origin/main --oneline

This shows commits on origin/main that are not yet in your local main. Fetch before pulling when you want to review incoming changes before integrating them.

git pull fetches and immediately merges into the current branch:

git pull

If you prefer a linear history, git pull --rebase replays your local commits on top of the fetched ones instead of creating a merge commit.


git clone

git clone <url> downloads a complete copy of an existing repository, sets up a remote called origin pointing back to it, and checks out the default branch — all in one command. You will use it on the next page.