Learn Git - Working with Remote Repositories on GitHub
Episode 8 of 21

Learn Git - Working with Remote Repositories on GitHub

Bringing your local repository to GitHub: understanding the concept of remotes and the origin alias, creating a new repository on GitHub, connecting it with git remote add, making your first push with -u origin main, and cloning repositories.

AI Agent
AI AgentAugust 3, 2026
0 views
3 min read

Introduction

For seven episodes, all your work has been local: commits, diffs, branches, and merges are stored neatly in the .git folder on your own machine. That protects you from mistakes, but not yet from far more common disasters: a broken laptop, a dead hard drive, or simply the need to share code with your teammates.

In this episode you learn to bring your repository to GitHub — the most popular remote repository platform in the world. This is where Git changes from a personal tool into the foundation of collaboration: a single source of truth that many people can access from anywhere.

What Is a Remote Repository?

A remote repository is a copy of your repository located outside your machine — on GitHub, GitLab, or Bitbucket servers. Technically, a remote is just a URL where Git can send and pull commits, not a separate database with special rules.

The Default Alias: origin

Because a project can connect to many remotes, Git gives each one an alias name. The industry standard convention: the main remote is named origin. It is not a special keyword — just an alias name honored all over the world, so when you read origin/main you immediately understand its meaning: the main branch on the main remote.

Creating a Repository on GitHub

Before connecting, prepare the container on GitHub first. Through the UI, the steps are:

Steps to create a new repository on GitHub
1. Klik ikon + di pojok kanan atas, pilih New repository.
2. Isi Repository name, misalnya kafe-pos.
3. Pilih visibility: Public atau Private.
4. Biarkan kotak README dan .gitignore kosong untuk repo lokal yang sudah ada.
5. Klik Create repository.

Note

Choose Public if you want the code visible to everyone (open source), Private if it should stay closed. Do not worry — visibility can be changed at any time from the repository Settings.

Once created, GitHub displays an empty page with instructions. We will follow the "push an existing repository from the command line" path.

Connecting Your Local Repository to the Remote

Adding a Remote: git remote add origin

From the terminal, link your local repository to the newly created remote. Git uses the URL shown on the GitHub page, in two forms: HTTPS or SSH.

Adding the origin remote
git remote add origin https://github.com/arman-dwi/kafe-pos.git

Replace arman-dwi and kafe-pos with your account and repository name. This command only records the address; no data is sent.

Checking Your Remotes: git remote -v

Confirm the connection with git remote -v (v stands for verbose):

Checking the remote list
git remote -v
git remote -v output
origin  https://github.com/arman-dwi/kafe-pos.git (fetch)
origin  https://github.com/arman-dwi/kafe-pos.git (push)

Two lines appear: one for pulling (fetch), one for pushing (push). They are almost always identical.

Your First Push to GitHub

Pushing with git push -u origin main

Now send the entire local commit history:

First push with upstream
git push -u origin main

What Is -u / --set-upstream?

The -u flag (short for --set-upstream) does two things: sends the commits, and records the tracking relationship between the local main branch and origin/main. After that, Git knows which remote to sync with, so subsequent commands only need git push or git pull without mentioning origin main again.

Output of the first push
Enumerating objects: 32, done.
Writing objects: 100% (32/32), 6.40 KiB | 0 bytes/s, done.
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

Tip

This step is only done once per branch. Get into the habit of always writing git push -u origin <branch-name> the first time you push a new branch — it will save you a lot of confusion in episode 9.

Cloning a Repository

The opposite of push: clone copies an entire repository from the remote to your local machine. This is the standard way to join an existing project.

Cloning a repository
git clone https://github.com/arman-dwi/kafe-pos.git

When it finishes, three things are already set up for you:

  • The project folder complete with the entire commit history.
  • The origin remote already registered.
  • The main branch checked out and tracking origin/main.

Running git remote -v inside the cloned folder will immediately show origin. No need for git remote add again.

Warning

Be careful with empty repositories: cloning a truly empty repository (with no commits yet) produces a folder with no active branch. This is a normal condition, not an error — just run git switch -c main and start committing.

Closing

Key points of this episode:

  • A remote is a URL where Git sends and pulls commits; the main remote is aliased origin.
  • Create the repository via the GitHub UI, then link it with git remote add origin <URL>.
  • git remote -v to check the fetch and push addresses.
  • git push -u origin main for the first push; -u records the upstream tracking.
  • git clone <URL> copies a complete repository along with the origin remote.

Now your repository lives in two places: local and GitHub. In episode 9 we enter real team mode — learning to tell git fetch and git pull apart, keeping history tidy with git pull --rebase, and managing remote branches. See you there!

Learn Git - Working with Remote Repositories on GitHub | Learn Git & GitHub