Learn to publish your Go module on GitHub by initializing a repository, committing changes, tagging releases, and updating your module for public use.
In this lesson, you’ll learn how to publish your Go module on GitHub. Follow the steps below to initialize your Git repository, commit your changes, tag your release, and update your module for public use.
Start by converting your unversioned project directory into a Git repository. Begin in your project’s root directory, as illustrated below:
Log into your GitHub account and create a new, empty repository. Copy the repository URL provided by GitHub for future use.Run the following command to initialize the Git repository:
Copy
Ask AI
git init
Initializing the repository sets up the necessary metadata, transforming your project directory into a version-controlled environment.
Check the current status of your repository. Here, a custom “go status” command (used to illustrate changes) triggers an error message since it’s not a valid Go command:
Copy
Ask AI
cryptit on 🎸 master [?] via v1.19.3> go statusgo status: unknown commandRun 'go help' for usage.
At this point, your project includes the encrypt and decrypt packages, along with the go.mod and main.go files. Stage and commit these files with an appropriate message:
Desktop/kodekloud/learn via v1.19.3$ go get github.com/Priyanka-yadavv/[email protected]go: added github.com/Priyanka-yadavv/cryptit v0.1.0Desktop/kodekloud/learn via v1.19.3
With your module now published on GitHub, you can easily share and reuse your code. This practice simplifies dependency management and supports semantic versioning.
That concludes this lesson on publishing a module to GitHub. Happy coding, and we’ll see you in the next lesson!