About Bart Bakker

Bart is a technologist who specializes in agile software development. He is passionate about creating working software that is easy to change and to maintain.

Signing Git tags

One of Git’s interesting features is definitely the ability to sign tags. Using your GPG key-pair you can create a signed tag. Anyone with your public key can verify that you are the true creator of that tag.

Why you should sign your tags

As Git is a distributed version control system (DVCS) you need a to verify the source of a release. Just like you verify checksums of releases you download to make sure it’s the release you expect it to be (you do verify your downloads, don’t you?!), you want to prove that the tag is created by the expected trusted source.

While signing tags is more important in open-source projects, it’s generally also a good idea for your private projects. See the signing as one of the core team members placing stamp in your repository, as they release a version of their software.

Also signing tags is dead easy as I’ll show you next.

Create a signed tag

To create a signed tag all you need is a Git repository and a GPG private key you want to use to sign the tag. Don’t worry if you don’t have GPG set up yet, I’ll cover this a little later.

To make things really easy set your GPG signing key as a global configuration setting. Obviously you don’t need to do this – especially if you have more than one account (e.g. work and private) you want multiple signing keys so set them up per repository (discard the global option).

$ git config --global user.signingkey [gpg-key-id]

Now all you need to do is create a tag and sign it.

$ git tag --sign [signed-tag-name]

Verify a tag

Verifying tags is as easy as creating one.

$ git tag --verify [signed-tag-name]

However, you need the signer’s public key to be able to verify the commit. Most maintainers put their public key in a special object in the repository – an object that can only be reached from a specific tag (or of course its own SHA).

You can make your public key available in a tag as follows.

$ gpg -a --export [gpg-key-id] | git hash-object -w --stdin
    [object SHA]

    $ git tag -a [object SHA] maintainer-pgp-pub

To import a maintainer’s public key into your keyring you can show the tag.

$ git show maintainer-pgp-pub | gpg --import

Generally it is also a good idea to leave instructions on importing your public key and verifying tags in the tag message.

Create a GPG key

If you don’t have a GPG key pair yet it’s about time to create one. If you’re in doubt most likely you don’t have any but it’s always a good idea to check your list of GPG keys.

$ gpg --list-keys

If you need to, generate a key. Choose the RSA algorithm if you can as DSA only supports up to 1024 bits.

$ gpg --gen-key

As you see using GPG and signing Git tags is really simple, so there’s actually no reason not to sign your tags.

So go and sign and verify!
 

Reference: Signing Git tags from our JCG partner Bart Bakker at the Software Craft blog.
Related Whitepaper:

Software Architecture

This guide will introduce you to the world of Software Architecture!

This 162 page guide will cover topics within the field of software architecture including: software architecture as a solution balancing the concerns of different stakeholders, quality assurance, methods to describe and evaluate architectures, the influence of architecture on reuse, and the life cycle of a system and its architecture. This guide concludes with a comparison between the professions of software architect and software engineer.

Get it Now!  

Leave a Reply


2 × = sixteen



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.