The Git cookbook

Git, you either love it for its power or hate it for it's ui. While I'm a trained git apologist and love its power and flexibility, I've also done a lot of git user support at work and in the #git IRC channel. I understand the frustration of the jumble of jargon, inconsistency and arcana that is the git UI and will help you dive into it!

If you have questions, comments or suggestions about any of the articles, please leave a comment on the article or in the issue tracker on GitLab. Suggestions for new articles are also very welcome!


Git and configuration files

Posted on Wed 17 August 2016 in Effective git usage • Tagged with configurationLeave a comment

How do you keep local changes to the configuration files in your project's repository? Should you use update-index, or is there a better way to ignore local changes. None of that nonsense, your configuration files do not belong there and in this article I'll show you why, and what alternatives there are for your configuration files.

Continue reading

Describing the relationship between commits

Posted on Sun 20 March 2016 in Effective git usage • Tagged with hooks, describe, ancestor, merge-base, branch, rev-parseLeave a comment

Unless you have only one commit in your repository, no commit stands on it own and all commits can be related to each other. These relationships can be described in multiple ways, from exact revision walking paths to a vague 'are these commits even related'?

Continue reading

Undoing all kinds of mistakes

Posted on Sun 20 March 2016 in Effective git usage • Tagged with checkout, reset, rebase, rewrite, undo, stashLeave a comment

Git understands that humans are not perfect, and that often we want to change our minds about what we did. To help with this, git offers many tools to undo our changes and even change history. The trick is knowing when to use which tool.

Continue reading

Quickly seeing the age of your branches

Posted on Sat 12 December 2015 in Plumbing is awesome • Tagged with plumbing, for-each-ref, merge-base, log, branchLeave a comment

Want to know how old all your branches are? You can of course browse your logs, but git can tell you what you want to know in one command (if you're willing to call some shell golfing a single command)

Continue reading

Repairing and recovering broken git repositories

Posted on Tue 08 December 2015 in Troubleshooting • Tagged with corruption, recovery, reflogLeave a comment

Git tries very hard not to forget anything you have ever committed, but that only works as long as your .git directory is intact. What do you do if it gets corrupted? Many parts of it can be recovered and in this article we find out how to do this.

Continue reading

How to back up a git repository

Posted on Mon 07 December 2015 in Repository maintenance • Tagged with backupLeave a comment

Backing up a git repository isn't as simple as cloning it, even creating tarballs may not be good enough for backing up. And if you think rsync has got you covered, think again! Let's explore some backup methods and how to break their assumptions with git. Of course we also explain how to correctly back up a git repository.

Continue reading

Previewing a merge result

Posted on Mon 07 December 2015 in Effective git usage • Tagged with merge, diffLeave a comment

Can you preview what the result of a merge would look like? Sort of, here you can learn how.

Continue reading

Rebasing illustrated

Posted on Wed 18 November 2015 in Commit grooming • Tagged with rebase, rewriteLeave a comment

We dive into the git rebase command and take away all the fear around it.

Continue reading

Extending git's bash completion for your own commands

Posted on Sun 08 November 2015 in Extending git • Tagged with bashLeave a comment

Git has pretty decent and extensible bash completion. We'll teach you how to extend this completion for your own git subcommands.

Continue reading

Deleting branches that have been merged

Posted on Sat 07 November 2015 in Repository maintenance • Tagged with branch, remoteLeave a comment

Learn how to to find branches that have been merged into your main branch and how to delete them.

Continue reading

Getting rid of submodules

Posted on Sat 07 November 2015 in Repository maintenance • Tagged with submodulesLeave a comment

Getting rid of submodules is as cumbersome as any submodule operation. So let's have no more of it and delete some submodules.

Continue reading

The meaning of refs and refspecs

Posted on Sat 07 November 2015 in Background information • Tagged with refs, branch, tag, remote, github, pull-request, notes, gerrit, bisect, merge, filter-branch, replace, stashLeave a comment

Refs are one of git's core concepts. Learn here about all the different types of refs (many more than just tags and branches) and how they differ from each other.

Continue reading

Recovering from a detached head

Posted on Thu 05 November 2015 in Digging through history • Tagged with checkout, branch, bisect, submodules, refsLeave a comment

Unlike in real life, a detached head is pretty common in git. Find out how you can get into this situation and how to recover from it.

Continue reading

Removing unwanted data from git repositories

Posted on Thu 05 November 2015 in Commit grooming • Tagged with filter-branch, bfg, cleanup, rewriteLeave a comment

Ever committed something very large or sensitive? Find out how you can remove it from your repository.

Continue reading

Simple deployments with git

Posted on Thu 05 November 2015 in Git on the server • Tagged with hooks, post-receive, deployLeave a comment

While git is not a deployment tool, many people (attempt to) use it as one. So here are some recipes for doing deployments with git hooks in a safe and sane way.

Continue reading

Always using the latest and greatest git

Posted on Wed 04 November 2015 in Effective git usage • Tagged with next, installLeave a comment

Help testing Git development by using packages that integrate with Ubuntu, Debian CentOS and Fedora.

Continue reading

Dealing with misconfigured https repositories

Posted on Wed 04 November 2015 in Troubleshooting • Tagged with http, https, dangerLeave a comment

You should never have to disable SSL verification, but sometimes you do not control the host you must get some data from. If you must do so, learn here how to do this without firther compromising your security.

Continue reading

Using credential helpers to cache passwords

Posted on Wed 04 November 2015 in Effective git usage • Tagged with authentication, httpLeave a comment

Never type your passwords again, but store them safely in a password manager Git can use.

Continue reading

Serving git's smart http protocol and a web interface with Apache

Posted on Tue 03 November 2015 in Git on the server • Tagged with apache, server, gitweb, cgit, http, https, authenticationLeave a comment

From zero to fully working web server in 2 configuration files, including smart HTTP, ssl, authentication, and cgit or gitweb.

Continue reading

Using multiple post-receive hooks

Posted on Tue 03 November 2015 in Git on the server • Tagged with hooks, post-receiveLeave a comment

Workaround for a common pitfall for some git hooks: consuming all input.

Continue reading

Showing all branches and their relationships

Posted on Sun 01 November 2015 in Digging through history • Tagged with log, branchLeave a comment

You don't need a graphical interface to see all your branches and their relationships.

Continue reading