To install Go on your computer, follow the official installation guide.
You should install the latest official Go binary for your system (if not available, install from source). If you plan to cross compile Sia, see Cross Compilation with Go 1.5 by Dave Cheney.
- To get familiar with the language, start with the official Tour of Go.
- Move onto How to Write Go Code to learn how to organize Go packages and use the go tool.
- Finish with the Effective Go guide.
To build Sia on your machine, enter the following on the command line:
# Download Sia and its dependencies
# Binaries will be installed in $GOPATH/bin
$ go get -u go.sia.tech/siad/...
# Switch to directory containing Sia source code
$ cd $GOPATH/src/go.sia.tech/siad
# You have three Sia builds to choose from.
# To build the standard release binary:
$ make release
# Or to build the release binary with race detection and an array debugging
# asserts:
$ make release-race
# Or to build the developer binary (with a different genesis block, faster
# block times, and other changes):
$ make dev
# Or build the developer binary with race detection:
$ make dev-race
# Build the debugger binary:
$ make debug
# Or build debugger binary with race detection:
$ make debug-race
Install git on your machine according to these instructions in the Pro Git book.
You will first need to set up global settings using the command line.
$ git config --global user.name "Your Name"
$ git config --global user.email [email protected]
# Tell git to remember your login information for a certain amount of time.
# Default time is 15 minutes:
$ git config --global credential.helper cache
# Or you can choose a different amount of time:
$ git config --global credential.helper "cache --timeout=[seconds]"
While logged into your GitLab account, navigate to the Sia repository
and click the 'Fork' button in the upper righthand corner. Your account now
has a 'forked' copy of the original repo at
https://gitlab.com/<your GitLab username>/Sia
.
When you installed Sia using go get
, the go tool put the Sia source code in
$GOPATH/src/go.sia.tech/siad. Change to that directory and set up
your fork as a git remote:
$ cd $GOPATH/src/go.sia.tech/siad
# Add your fork as a remote. Name it whatever is convenient,
# e.g your GitLab username
$ git remote add <remote name> https://gitlab.com/<username>/Sia.git
# Or if you use an SSH key, create the remote with the following
$ git remote add <remote name> [email protected]:<username>/Sia.git
Right now your git local repository only has one branch (called 'master' by default). If you want to make changes, add a new branch and make your changes there. You should maintain master as an up-to-date copy of the repository's master branch.
To create and checkout a new branch:
# If you're not already in the right directory:
$ cd $GOPATH/src/go.sia.tech/siad
# Make sure you're on branch master
$ git checkout master
# Create and checkout a new branch
$ git checkout -b <branch>
Now write some code while the new branch is checked out.
Only implement one logical change per branch. If you're working on several
things at once, make multiple branches. To switch between branches you're
working on, you have to stash the changes in the branch you're switching from by
running git stash
, which tucks away all changes since the last commit.
# Stash changes to current branch.
$ git stash
# Checkout other branch.
$ git checkout <branch>
...
# Make changes
...
# Return to first branch:
$ git checkout <branch 1>
# View a list of stashes and their corresponding hashes.
$ git stash list
# Reapply changes from the stash you want to recover and remove that stash from.
# the list
$ git stash pop <hash>
To learn more about branching, see Using the Fork-and-Branch Git Workflow and Pro Git - Branches in a Nutshell. For more on stashing, see Pro Git - Stashing and Cleaning.
Be sure to follow the conventions detailed in docs/Developers.md and Merge Requests.md. We will reject merge requests that do not satisfy these best practices.
Once you've finished making changes, stage and commit your changes then update your fork on GitLab:
# Make sure the code is up to date with the original repo:
$ git checkout master
$ git pull origin master
# Checkout branch with changes.
$ git checkout <branch>
$ git rebase master
# Before every merge request, you should run `make test-long`
# to test your code and fix formatting and style problems.
$ make test-long
# If all goes well, proceed to staging your changed files:
$ git add <changed files>
# Use `git status` to see what files have been staged.
$ git status
# Commit your changes. If you just run `commit`, a text editor will pop up for
# you to enter a description of your changes.
$ git commit -m "Add new tests for CommitSync method"
# Push the changes to your fork on GitLab, which you should have set up as a
# remote already.
$ git push <fork remote> <branch>
Once you've tested your new code and pushed changes to your fork, navigate to
your fork at https://gitlab.com/<username>/Sia
in your browser.
Switch to the branch you've made changes on by selecting it from the list on the
upper left. Then click 'New merge request' on the upper right.
Once you have made the merge request, we will review your code. We will reject code that is unsafe, difficult to read, or otherwise violates the conventions outlined in our Developers document.
Here's a sample code review comment:
If you want to tweak code for which you've already submitted a merge request,
push the updated code to your fork with git push -f <fork remote> <branch>
and
summarize the changes you've made in a comment on the merge request page on
GitLab.
Once we have accepted your changes and merged them into the original repo, you have some cleanup to do:
# Update local master branch to reflect changes in origin (the original
# repo).
$ git pull origin master
# Delete the branch you made the merge request from.
$ git branch -d <branch>
# Delete the remote branch on your fork.
$ git push <fork remote> :<branch>
# Update your fork.
$ git push <fork remote> master
- How to into git (and GitHub) by Luke Champine
- Official resources for learning Git
If you'd like to contribute to Sia but don't have any specific ideas, writing tests is a good way to get your feet wet. See Running and Writing Tests for Sia to get started.
To learn more about how various parts of the code base work, head over to our Resources page in our doc folder.
Feel free to ask for help on the #core-dev channel on discord.