Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Working with GitHub: Remotes, Push, Pull, and CollaborationLesson 3.1

Connecting Local Repositories to GitHub

git remote, git push, git clone, origin, remote URL, SSH vs HTTPS, GitHub repository creation

Connecting Local Repositories to GitHub

GitHub is a cloud hosting platform for Git repositories. Once your local repository is connected to GitHub, you can share your code, collaborate with others, and back up your history remotely.

Creating a GitHub Repository

Log in to GitHub and click the plus icon to create a new repository. Give it a name, choose public or private visibility, and optionally add a README. Do not initialize with a README if you are connecting an existing local repository.

Adding a Remote

A remote is a reference to a repository hosted on a server. Add GitHub as your remote origin:

git remote add origin https://github.com/username/repo-name.git

The name origin is a convention — it means the main remote server. You can have multiple remotes with different names.

Pushing for the First Time

git push -u origin main

The -u flag sets the upstream tracking relationship. After this, you can simply run git push and Git knows where to push.

SSH vs HTTPS Authentication

HTTPS requires a username and personal access token. SSH uses a key pair — a private key on your machine and a public key registered on GitHub. SSH is more convenient for daily use because it does not require entering credentials. Set up SSH with ssh-keygen -t ed25519 -C "email@example.com" and add the public key to your GitHub account under Settings > SSH Keys.

Up next

Fetching, Pulling, and Pushing Changes

Sign in to track progress