Git & GitHub

Version Control System

A version control system, or VCS, tracks the history of changes as people and teams collaborate on projects together. As developers make changes to the project, any earlier version of the project can be recovered at any time.

Developers can review project history to find out:

  • Which changes were made?

  • Who made the changes?

  • When were the changes made?

  • Why were changes needed?

VCSs give each contributor a unified and consistent view of a project, surfacing work that's already in progress. Seeing a transparent history of changes, who made them, and how they contribute to the development of a project helps team members stay aligned while working independently.

In a distributed version control system, every developer has a full copy of the project and project history. Unlike once popular centralized version control systems, DVCSs don't need a constant connection to a central repository.

GitHub, on the other hand, is a web-based platform that provides hosting for Git repositories. It is a popular platform for developers to collaborate on open-source projects, share code, and work together on projects.

In this blog post, we will explore the basics of Git and GitHub, and some essential Git commands that every developer should know.

Git

Git is the most popular distributed version control system.

  • It enables developers and data scientists to track code, merge changes, and revert to older versions. It allows you to sync changes with a remote server.

  • Due to its flexibility and popularity, Git has become an industry standard as it supports almost all development environments, command-line tools, and operating systems.

  • Businesses using Git can break down team communication barriers and keep them focused on doing their best work. Plus, Git makes it possible to align experts across a business to collaborate on major projects.

Repository

A repository, or Git project, encompasses the entire collection of files and folders associated with a project, along with each file's revision history. The file history appears as snapshots in time called commits. The commits can be organized into multiple lines of development called branches. Because Git is a DVCS, repositories are self-contained units and anyone who has a copy of the repository can access the entire codebase and its history. Using the command line or other ease-of-use interfaces, a Git repository also allows for: interaction with the history, cloning the repository, creating branches, committing, merging, comparing changes across versions of code, and more.

Through platforms like GitHub, Git also provides more opportunities for project transparency and collaboration. Public repositories help teams work together to build the best possible final product.

How does Git work?

Git stores your files and their development history in a local repository. Whenever you save changes you have made, Git creates a commit. A commit is a snapshot of current files. These commits are linked with each other, forming a development history graph, as shown below. It allows us to revert back to the previous commit, compare changes, and view the progress of the development project - Azure DevOps. The commits are identified by a unique hash which is used to compare and revert the changes made.

GitHub

GitHub is a cloud software development platform. It is commonly used for saving files, tracking changes, and collaborating on development projects. In recent years, GitHub has become the most popular social platform for software development communities. Individuals can contribute to open-source projects and bug reports, discuss new projects, and discover new tools.

GitHub builds collaboration directly into the development process. Work is organized into repositories where developers can outline requirements or directions and set expectations for team members. Then, using the GitHub flow, developers simply create a branch to work on updates, commit changes to save them, open a pull request to propose and discuss changes, and merge pull requests once everyone is on the same page.

Basic Git Commands

  • git init - Initializes a new Git repository in the current directory.

  • git add - Adds files or changes to the staging area. This prepares the changes to be committed to the repository.

  • git commit - Commits changes to the repository with a message describing the changes made.

  • git status - Shows the status of the repository, including any changes made to the codebase.

  • git log - This shows a log of all the commits made to the repository.

  • git clone - Copies an existing Git repository to a new location.

  • git pull - Fetches and merges change from the remote repository to the local storage.

  • git push - Pushes changes from the local repository to the remote repository.

Conclusion

In summary, Git and GitHub are essential tools for any developer working on a codebase. Git provides a way to manage changes to the codebase, while GitHub provides a platform for collaboration and sharing code with other developers.

Understanding the basics of Git and GitHub, and the essential Git commands will help any developer become more productive and efficient in their work.