Git
In short
Git is a free, open-source distributed version control system that tracks changes to files over time, so developers can collaborate and undo mistakes.
What is Git?
Git keeps a complete history of a project by recording snapshots of its files, called commits. At any point you can see what changed, who changed it, and why, and you can return to an earlier version if something breaks. Linus Torvalds created Git in 2005 to manage development of the Linux kernel, and it is now the most widely used version control system in the world.
Git is distributed, which means every developer has a full copy of the repository, including its entire history, on their own machine. Most work, like committing, viewing history, and creating branches, happens locally and even works offline. Developers share changes by pushing to and pulling from a remote repository, often hosted on a platform such as GitHub, GitLab, or Bitbucket.
A save system in a video game is a common analogy for Git. Each commit is a save point you can reload, and branches let you try a risky path without losing your main progress. The typical workflow is to edit files, stage (select) the changes you want to keep with git add, and save them as a commit with git commit.
Git is often confused with GitHub. Git is the version control tool itself, which runs on your computer, while GitHub is an online service that hosts Git repositories and adds collaboration features like pull requests and issue tracking.
At a glance
Key takeaways
- Git is a distributed version control system: every clone contains the full history.
- Changes are saved as commits, which act as restorable snapshots.
- Branches let you work on features in isolation and merge them later.
- Git is the tool; GitHub, GitLab, and Bitbucket are services that host Git repositories.
Example
# Start tracking a project
git init
# Stage changes and save a snapshot
git add .
git commit -m "Add homepage layout"
# Connect to a remote repository and upload your work
git remote add origin https://github.com/example/my-project.git
git push -u origin main
# See the project history
git log --onelineReaders ask
What is the difference between Git and GitHub?
Git is the version control software that tracks changes on your computer. GitHub is a website and service that hosts Git repositories online and adds collaboration features such as pull requests, code review, and issues.
What is a Git repository?
A repository, or repo, is a project folder tracked by Git, including all of its files and its complete history of commits. Git stores this history in a hidden .git directory inside the project.
Is Git free to use?
Yes. Git is free and open-source software released under the GNU General Public License version 2, and it runs on Windows, macOS, and Linux.
Often compared
See also
- CommitVersion Control, p. 5A commit is a saved snapshot of a project's files in Git, recorded with a unique ID, an author, a timestamp, and a message describing what changed.
- BranchVersion Control, p. 2A branch in Git is an independent line of development that lets you work on a feature or fix in isolation, without affecting the main code until you merge it.
- MergeVersion Control, p. 29A merge in Git combines the changes from one branch into another, joining separate lines of development back together into a single, shared history.
- Pull RequestVersion Control, p. 32A pull request is a proposal to merge changes from one branch into another, giving teammates a place to review, discuss, and test the code before it is merged.
- RebaseVersion Control, p. 33A rebase in Git replays a branch's commits on top of another commit, rewriting history to produce a cleaner, linear sequence of changes without merge commits.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
- GitHubVersion Control, p. 25GitHub is a platform for hosting Git repositories and working on code together, with pull requests, code review, issues and the largest open-source community.
- Version ControlVersion Control, p. 39Version control is a system that records every change to a set of files, so you can see who changed what, return to earlier versions and work in parallel.
Sources
Spotted a mistake or something missing on this page?Suggest an edit