Skip to main content
In this lesson we’ll publish a Go module to GitHub and then consume that published version from another local module. Follow the steps below to initialize a repository, tag a release, push it to GitHub, and update a consuming module to use the released version.

Overview

  • Initialize a local Git repository and connect it to a GitHub remote.
  • Commit and tag a release (e.g. v0.1.0).
  • Push the branch and tag to GitHub.
  • Remove any local replace directives in the consuming module and fetch the released version with go get.
  • Verify the consuming module uses the published release.

1. Initialize a Git repository

From the root of your unversioned project directory:
This creates an empty Git repository in the current directory.

2. Add a remote and verify it

Copy your repository URL from GitHub (for example: https://github.com/Priyanka-yadavv/cryptit.git) and add it as the origin remote:
Verify the remote:
Expected output:

3. Stage and commit your files

Add your module files (for example, encrypt/, decrypt/, go.mod, main.go) and create a commit:
Example commit output:

4. Tag the release

Create a version tag for this set of changes. Semantic version tags are recommended:
List tags to confirm:

5. Push the branch and tag to GitHub

If you haven’t pushed the branch yet, push it (replace master with your branch name if different):
Then push the tag:
Or push all tags at once:
Typical output:
Make sure you push both the branch and the tag. Tags are not automatically pushed with branches unless you use git push --tags.

6. Verify on GitHub

After pushing, open your repository on GitHub and confirm the files and tag appear.
A dark-mode GitHub repository page for "Priyanka-yadavv/cryptit" showing a v0.1.0 tag and a file list with folders named decrypt and encrypt plus go.mod and main.go. The right sidebar shows "Go module example" and repo stats (0 stars, 1 watching).
You should see the folder structure and the v0.1.0 tag on the repository page.

7. Remove local replace in the consuming module

If a consuming module previously used a replace directive to point to a local copy of your module, remove that directive so Go can fetch the published version from GitHub. Example go.mod before removing replace:
Delete the replace line. After removing it, go can resolve and download the module from the remote repository.

8. Fetch the published version with go get

In the consuming module run:
You should see:
Your go.mod will reflect the published version (it may show // indirect if not directly referenced by imports):

9. Run your main program to verify

In your consuming module (for example example.com/learn) ensure you import and call the function from the published module. Example main.go:
Run it:
Example output:
This confirms the consuming module uses the published cryptit module fetched from GitHub (not a local replacement).

Quick reference: common Git commands for publishing

Updating the module later

When you change the module and want to publish a new release:
  1. Bump the version tag (for example v0.1.1).
  2. Commit required changes.
  3. Create and push the new tag: git tag v0.1.1 && git push origin v0.1.1
  4. In the consuming module: go get github.com/Priyanka-yadavv/cryptit@v0.1.1
Always increment the module version (tag) for new releases. Consumers should use go get <module>@<tag> to fetch a specific release.
That’s it — you’ve published a Go module to GitHub and consumed it from another module.

Watch Video