Git is a crucial tool in software engineering, serving as a version history for code in a similar way to Google History or Confluence history. When we need to restore an old code, we simply “revert” to an earlier version. However, that’s just the tip of the iceberg when it comes to this powerful system.
In software engineering, a “commit” refers to the act of saving changes to a code repository. This is an essential part of the software development process as it allows developers to keep track of changes made to the code over time. Each commit is accompanied by a message that describes the changes made, allowing for a better understanding of the code’s evolution and history.
Unlike Google Docs, where changes are saved automatically, with Git, we create a new version (commit) manually. This is because half-finished code doesn’t work, and each commit represents a working version of the code. To handle multiple parallel versions of the code, Git uses a concept called “branching.” A branch is essentially a separate line of development within the same code repository, allowing multiple developers to work on different parts of a codebase or experiment with new features without interfering with the main codebase.
In summary, Git is a powerful version control system that helps software developers keep track of changes to the codebase. Commits serve as versions of the code, allowing for a better understanding of its history. Branching enables multiple developers to work on various parts of the codebase independently, making it an essential tool for modern software engineering.
When coding, it’s crucial to have backups in case anything goes wrong with your local files. Popular cloud storage solutions like Google Drive, One Drive, and iCloud offer online backups that allow for easy recovery of lost files. But when it comes to code, simply storing files online isn’t enough. That’s where GitHub comes in.
GitHub is essentially the equivalent of Google Drive for Git, specifically designed for storing Git repositories. So what is Git? Git is a type of version control system that allows developers to keep track of changes made to code over time. With version control, you’ll always have access to previous versions, and you’ll know who made each change and when.
Similar services to GitHub include Bitbucket and Gitlab. But when it comes to popularity, GitHub is king. According to a 2020 survey by Stack Overflow, roughly 82% of respondents use GitHub as their primary code repository.
So how do you get started with GitHub? First, you’ll need to create a repository (repo) on GitHub to store your code. Once you’ve got that set up, you’ll need to link your local repository to your remote repository (on GitHub). This allows you to easily push your local changes to GitHub so that you have an online backup. Conversely, you can also pull changes from GitHub to your local machine so you can work on the code from multiple locations.
The workflow for pushing to GitHub is simply called “pushing,” and the workflow for downloading changes from GitHub is called “pulling.” These commands are executed through Git. By pushing your changes to GitHub, you’ll know that you always have an up-to-date backup of your code.
GitHub is one of the most popular code version control tools, and it provides a great platform for managing merging and branching of code. Branching is a powerful way to keep your code organized while creating a bug fix or new feature by creating a separate branch for them.
This is an example on how merging works
The Feature Branch Workflow is a popular way to manage branching in code:
Code conflicts can arise when working in a team, and this is where things can get a little tricky. When conflicts happen, it’s up to the author of the code to decide what to do to solve the conflict.
Creating a pull request on GitHub enables other developers working on the project to review the code and ensure it meets quality standards before it’s merged into the main branch. When creating a pull request, you can add descriptions, select commits to compare, and communicate with your team about the changes you’ve made.
Once the code has been reviewed, it’s time to merge it into the master branch. Merging on GitHub is a stress-free process that reduces the risks and errors that can occur when performing merges manually.