← Back to Git Course | Chapter 4: Remote Repositories | Lesson 8 of 11

Git GitHub Introduction

What is GitHub?

GitHub is a web-based hosting platform for Git repositories that adds collaboration tools -- issues, pull requests, code review -- on top of raw Git. You connect a local repository to it the same way as any other remote, using git remote add.

Example: What is GitHub?

bash
git remote add origin https://github.com/user/repo.git

Cloning from GitHub

Any public repository on GitHub can be cloned by anyone with either its HTTPS URL or its SSH URL -- HTTPS is simpler to set up initially, while SSH avoids re-entering credentials once your key is configured.

Example: Cloning from GitHub

bash
git clone https://github.com/user/repo.git
git clone [email protected]:user/repo.git

Forking and Pull Requests

Forking creates your own personal copy of someone else's repository under your GitHub account; adding the original as an upstream remote alongside your fork's origin lets you keep pulling in the original project's updates over time.

Example: Forking and Pull Requests

bash
git remote add upstream https://github.com/original/repo.git
git fetch upstream

Personal Access Tokens

Since 2021, GitHub requires a Personal Access Token instead of your account password for command-line authentication over HTTPS -- you generate one in GitHub's settings and configure Git to use it like a password.

Example: Personal Access Tokens

bash
git clone https://<token>@github.com/user/repo.git

Linking an Existing Project

To publish a project that already exists locally, run git init, git add, and git commit as usual, then create an empty repository on GitHub, add it as a remote, and push -- GitHub never needs to see your code until that final push.

Example: Linking an Existing Project

bash
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/user/repo.git
git push -u origin main

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.