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

Git GitHub Introduction

GitHub is like a giant playground for code, where you store your projects online and chat, suggest changes and help each other with them.
Syntax
bash
git remote add origin https://github.com/user/repo.git
git clone https://github.com/user/repo.git

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
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Confusing Git and GitHub, when GitHub is a hosting service and Git is the tool.
  2. Cloning with HTTPS and being asked for a password, which GitHub no longer accepts; use a personal access token or SSH.
  3. Editing a fork's files and expecting the original repository to change, when you must open a pull request.

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.