Working with Git #

Version control is a staple part of the development cycle and it is important we (the entire team) understand it properly. It is not an exaggeration to say that this is one of most fundamental skills of any programmer.

While there are multiple types of version control systems available, we have defaulted to using git in all cases. It is ubiquitous and the only difference among teams is where the repository is hosted and what kind of branching workflow is followed. At Axelerant, we always use git, mostly work with Github, and encourage trunk-based development workflows.

Setting up Git

Setting up Git is essential to keeping track of changes made to our files, collaborating with others, and maintaining our version control. We use the 'git config' command to set Git configuration values on a global or local project level.

Collaborating with Git

Contributing to a project using Git involves a collaborative process of creating, testing, and submitting changes, allowing for efficient and effective collaboration. Git's version control features enable contributors to track changes, create new branches, and merge proposed changes, while the distributed nature of Git allows for teammates to share their work, provide feedback, and collaborate in real-time. By utilizing Git's tools and workflows, contributors can work together to improve the quality of code, ensure project stability, and ultimately achieve success in their project’s goals.

Atomic Commits

An atomic commit means that commit serves a single purpose. It can be refactoring, new API, verbiage change, etc. If you combine the refactoring and verbiage change in a single commit, then the purpose of atomic commit loses its purpose.

Pull Request (PR)

A GitHub PR, or pull request, is a way to propose changes to the codebase. Once the changes are reviewed, they can be merged to the "main" branch. This process helps to ensure that changes are reviewed by someone else, which reduces the chances of any errors.

Branching and Merging

Git branching and merging are essential concepts for managing any software. By using branches, we can isolate different features or bug fixes, and merge them back into the main branch as soon as they are ready.

Git Workflow

Git Workflow is a set of practices and procedures used with the Git version control system to manage software development. It involves creating branches, committing changes, merging, and pushing changes back to a central repository. It is essential for collaborative software development and ensures effective management of project changes.

Working with Forks

Working with forks in GitHub allows us to create a copy of an existing repository and make changes to it without affecting the original project. We can use forks to experiment with new features, fix bugs, or contribute to open source projects.

Working with Large Files

Working with media files, such as images and videos, in Git can be challenging due to the large file sizes. Git was originally designed to handle code or config files that are mostly text and usually small, so it can struggle with large binary files. Storing media files in Git can also cause the repository size to grow quickly, which can slow down cloning and pushing changes.

Rolling Back Changes

In Git, to undo or reverse the effects of one or more commits or roll back changes, there are different ways depending on the situation and the desired outcome.

Rebasing

Git rebase is a command that integrates changes from one branch onto another. It can also be used to rewrite history by altering, removing, or combining commits.

Git hooks

Git hooks are scripts that are triggered during certain Git events, such as committing, pushing, or merging code changes.

Recovering Lost Commits

Git is a powerful version control system that allows us to track changes to our code over time. However, even with Git, it is possible to accidentally delete commits or make other mistakes that can lead to data loss. Git possesses features that can help recover lost commits.