Version control

Writing history

All our projects use Git, mostly with a repository hosted on GitHub.

Repo naming conventions

If the repo contains the source code of a site its name should be the main naked domain name of that site. It should be lowercased.

Sites that are hosted on a subdomain may use that subdomain in their name

If the repo concerns something else, for example a package, its name should be kebab-cased.

Branches

If you're going to remember one thing in this guide, remember this: Once a project has gone live, the main branch must always be stable. It should be safe to deploy the main branch to production at all times. All branches are assumed to be active; stale branches should get cleaned up accordingly.

Projects in initial development

Projects that aren't live yet have at least two branches: main and develop. Avoid committing directly on the main branch, always commit through develop.

Feature branches are optional, if you'd like to create a feature branch, make sure it's branched from develop, not main.

Live projects

Once a project goes live, the develop branch gets deleted. All future commits to main must be added through a feature branch. In most cases, it's preferred to squash your commits on merge.

There's no strict ruling on feature branch names, just make sure it's clear enough to know what they're for. Branches may only contain lowercase letters and hyphens.

Pull requests

Merging branches via GitHub pull requests isn't a requirement, but can be useful if:

Merging and rebasing

Ideally, rebase your branch regularly to reduce the chance of merge conflicts.

Commits

There's not strict ruling on commits in projects in initial development, however, descriptive commit messages are recommended. After a project has gone live, descriptive commit messages are required. Always use present tense in commit messages.

Ideally, prefer granular commits.

Git Tips

Creating granular commits with patch

If you've made multiple changes but want to split them into more granular commits, use git add -p. This will open an interactive session in which you can choose which chunks you want to stage for your commit.

Moving commits to a new branch

First, create your new branch, then revert the current branch, and finally checkout the new branch.

Don't do this to commits that have already been pushed without double checking with your collaborators!

git branch my-branch
git reset --hard HEAD~3 # OR git reset --hard <commit>
git checkout my-branch

Squashing commits already pushed

Only execute when you are sure that no-one else pushed changes during your commits.

First, copy the SHA from the commit previous to your commits that need to be squashed.

git reset --soft <commit>
git commit -m "your new message"
git push --force

Cleaning up local branches

After a while, you'll end up with a few stale branches in your local repository. Branches that don't exist upstream can be cleaned up with git remote prune origin. If you want to ensure you're not about to delete something important, add a --dry-run flag.

Resources