What is Git and how is it different from GitHub?
- Technology:
- Git
Quick answer
Git is a distributed version control system that tracks changes to files on your machine; GitHub is a hosting service for Git repositories that adds collaboration features such as pull requests, code review and CI.
Detailed explanation
Git records snapshots of a project as commits. Every clone holds the full history, so you can commit, branch, view logs and compare versions without a network connection. Branches are cheap pointers to commits, which is what makes feature branches and experiments practical.
GitHub, GitLab and Bitbucket host a copy of the repository on a server so a team can share it. On top of Git they add pull requests, code review, issue tracking, permissions and automation such as GitHub Actions. You can use Git without GitHub, but not the other way round.
In day-to-day work you commit locally with Git, push your branch to the hosted remote, open a pull request for review, and merge it once checks pass.
Example
git init # start tracking a project
git add src/app.js # stage a change
git commit -m "Add login form"
git remote add origin https://github.com/you/project.git
git push -u origin main # share it on GitHubHow to explain it in an interview
Git is the version control tool that runs locally and stores the full history in every clone. GitHub is a service that hosts Git repositories and adds pull requests, reviews, issues and CI on top. I use Git to commit and branch, and GitHub to share work and get it reviewed.
Key points
- Git: the version control tool, works offline
- GitHub: a hosting and collaboration platform for Git repositories
- Every Git clone contains the full history
Common mistakes
- Using "Git" and "GitHub" as the same thing.
- Thinking you need an internet connection to commit. Commits are local until you push.
Follow-up questions
- What is the difference between git fetch and git pull?
- What is a branch in Git?