In this post we are going to list the first steps to contribute to a Go lang open source project.
In this example, we'll simulate a contribution to Bubbletea repository.
1) Fork the project
The first step is to fork the project you want to contribute. Search the project on GitHub and click on Fork
: you'll get your own version of the repository <your_name>/bubbletea
.
2) Clone the fork project into your computer
Clone the forked version of bubbletea into your computer. For the sake of this example, let's say you've cloned the repository at /home/forked_bubbletea
on your computer.
3) Use your local forked repository
We'll create a new folder at /home/test_bubble
. Create a file main.go
with a simple example:
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
)
.
.
.
func main() {
p := tea.NewProgram(initialModel())
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
}
Create a go.mod
file by doing:
go mod init test_bubble
Then, we need to replace the library we want to contribute by our own version of the library. For this, we need to append this line at the end of the go.mod
file:
...
replace github.com/charmbracelet/bubbletea v0.20.0 => /home/forked_bubbletea
By doing this, when we call in main.go
the library bubbletea
, we are going to call our local version of the library. Therefore, we can change our local version of the library and instantly see the effects in our code.
4) Raise a pull request
Finally, after we changed and committed our local version of the repository, all we need to do is raise a pull request to the repository we want to contribute. For this, go to the repository you want to contribute and click Compare & pull request
.
Top comments (2)
Thanks for this guide, what are git commands to replicate the 'Compare & pull request' button on Github?
Hi Simone, basically you have to send your local changes to GitHub. So, go to the folder you've cloned the project (
/home/forked_bubbletea
in the example) and type the commands in the terminal: