Git is a distributed version control system which is used to manage and track changes to files within a project, particularly in software projects.
Created by Linus Torvalds in 2005, Git enables developers to collaborate efficiently and maintain a complete history of all changes made over time.
This system is essential in software development, as it facilitates collaboration between teams, ensuring that each member can work on their own copy of the code without interfering with the work of others. As it is distributed, each contributor has a complete copy of the repository, allowing them to work independently without an internet connection.
Git features
- Version control: tracks changes made to a project’s files. Each change is recorded as a new version or «commit», allowing you to revert to previous versions if necessary.
- Branches: it makes it easier to create branches, allowing you to work on different features or fixes independently. Each branch can be merged back into the main branch (usually called «main» or «master») once the work is complete and tested.
- Merger: allows you to merge changes made in different branches. This is useful for combining the work of several developers or merging a new feature into the main branch.
- History: users can access the change history, which shows who made which changes and when, along with an optional description of each commit.
- Restoration: it allows you to undo changes if something goes wrong, either by restoring a specific file or reverting to a previous version of the project.
How does Git work?
Git works by snapshots of the project rather than tracking changes line by line. Every time a commit is made, Git takes a snapshot of the current state of the files and stores references to those files. If there are no changes to a file, Git simply references the previous file rather than storing a new copy.
This makes Git extremely efficient in terms of storage and speed. Users can clone a repository (create a complete local copy), make changes and then «push» those changes to the central repository.
Git uses three main areas in its workflow:
- Working Directory (Working directory): where changes are made.
- Staging Area (Staging area): where the files to be included in the next commit are prepared.
- Repository (Repository): where all the commits and the project history are stored.
Advantages of Git
Git offers a range of advantages for use, and they are as follows:
- Effective collaboration: enables multiple developers to work on the same project at the same time without overwriting each other’s changes.
- Distributed: Unlike centralised systems, Git allows each developer to have a complete copy of the repository, which means they can work offline and recover their work from any node in the event of a failure.
- Performance: it is quick and efficient when managing large projects involving multiple developers.
- Full history: the full project history is available at any time, enabling detailed traceability.
The difference between Git and GitHub
Git is the version control system, whereas GitHub It is a cloud-based platform that hosts Git repositories.
GitHub enables developers to collaborate on projects, store their repositories online and use additional features such as code review, issues (for tracking bugs and tasks) and actions for workflow automation.
Whilst Git is a tool you can use locally, GitHub makes it easier to remote collaboration and provides a graphical interface and additional tools for working with Git.
A project can use Git without being on GitHub, but using both together offers a more comprehensive experience for open-source and collaborative projects.