If you’ve ever used Git and Github for a personal project, you’re probably familiar with these three commands: git add, git commit and git push. This is useful and all, but where Git really starts to shine is when it comes to working together with a team or community. This is also the point where Git can make your life a living hell. To help ease the pain, I’ve decided to collect and share the most important takeaways I’ve had when going through this process.

Contents

Workflow

Git Flow

As soon as more than one person is actively contributing to your codebase, a clean Git workflow is vital to ensure smooth collaboration. There are a few different models, but they all base around the idea of splitting off sections of work into separate branches so developers don’t get in each other’s way while working. After the work or feature in the branch is deemed completed. The changes will get merged into a shared main or develop branch, to integrate them into the project.

Pull Requests

Contributing Guidelines

All proper open source repositories contain guidelines for contributing. These are usually written in a file called CONTRIBUTING.md. These guidelines may contain anything you would want contributors to adhere to, but should definitely include the following concepts.

Commits

Branches

Naming scheme

Issues

Labels

Templates

Linters & Style guides

Advanced Git in practice

No matter how well defined your workflow and contributing guidelines are, there will come a point where you will have to resolve conflicts and rewrite the Git history manually.

Merge, rebase, cherry-pick

Useful commands

Show the git history with decoration depending on the branches.

git log --graph --decorate --pretty=oneline --abbrev-commit

Rebase a branch on to the top of your current branch

git rebase

Squash commits

git rebase -i

Cleaning up an existing repository

If you have come this far and are thinking tou yourself, this sounds amazing, I wish I had known this before I started working on my project, don’t despair. Firstly, you can start employing the concepts right now, for any future change to your codebase. Secondly, there is a way to enact your guidelines retrospectively, albeit not without effort.

Preparing to clean

Group Commits

List changes and commits you would want to group together. If you have been using pull requests in your repository, these are a good place to start grouping.

Ensure no one is watching

Make sure you are on a branch by yourself before changing the history. Rewriting Git histroy in shared branches with other developer’s work depending on the commits you are changing is a bad time.

References

  1. Header Image Source: https://en.wikipedia.org/wiki/Git#/media/File:Git-logo.svg
  2. Gitflow Workflow; Atlassian; Retrieved March 6, 2021