Git GitHub Introduction
In this page:
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?
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
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
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
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
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/user/repo.git
git push -u origin main
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: