Creating a Swift Package on github: Not as easy as I thought

When it comes to all things git, I’m useless. This should not be news to anyone.


I thought that setting up a git repo to be used with the package manager would be a no-brainer. After all, consuming a package just means sticking a dependency one-liner into an app package, right?

Here’s the Package.swift file I established, which I thought I’d just compile and use.

import PackageDescription
let package = Package (
    name: "myutility",
    dependencies: [
	.Package(url: "",
                 majorVersion: 1),

Not so quick.

Git Tags

As I was forced to learn, git tags don’t automatically push forward to github on your behalf. It took me forever until I figured this out, which I did by (finally) cloning a repo and running git tag. There was nothing there.

% git tag

And that, in a nutshell, was why all my attempts at building a simple test app ended up in tears and “swift-build: The dependency graph could not be satisfied” (or “satisfed” under earlier Swift builds).

Adding Tags

You add tags by using git tag, e.g.

git tag -a 1.0.0 -m "Version 1.0.0"

You can then see those tags either by using git tag without arguments:

% git tag

or with names (messages):

% git tag -n
1.0.0 Version 1.0.0

Those tags don’t head up to github until they’re pushed:

git push --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 176 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
 * [new tag] 1.0.0 -> 1.0.0

Only then will your dependencies, which rely on tag versions, start working.

Lily B adds: “`git push –tags` will push _all_ of your tags. If you only want to push one, you can just list it explicitly, e.g. `git push origin v1.0.0`”

Reading Tags

You can read your tags from the consumer end by hopping into the Packages folder. There you’ll find each dependency with the tag number listed at the end:

% ls
./ ../ SwiftString-1.0.0/

If you enter the package folder, you’ll find the complete repo clone, including all the .git files. There, once again, you can check for the tag and any associated message:

% cd SwiftString-1.0.0/
% ls
./		.git/		Makefile
../		.gitignore	Package.swift	Sources/
% git tag -n
1.0.0           Version 1.0.0

Hopefully this post will save someone the time I wasted today.


  • If you depend on PackageA, but packageA depends on packageB, in your project folder Packages, will packageA automatically clone packageB into your Packages folder or it’s own Packages folder?

    • Yes. It is what is known as a subdependency. I am doing some articles on my blog about swift package manager – come check it out: