GitHub Workflow

This guide assumes you have already cloned the upstream repo to your system via git clone, or via go get github.com/k0sproject/k0s.

Fork The Project

  1. Go to http://github.com/k0sproject/k0s
  2. On the top, right-hand side, click on “fork” and select your username for the fork destination.

Adding the Forked Remote

  1. export GITHUB_USER={ your github username }
  1. cd $WORKDIR/k0s
  2. git remote add $GITHUB_USER git@github.com:${GITHUB_USER}/k0s.git
  3. # Prevent push to Upstream
  4. git remote set-url --push origin no_push
  5. # Set your fork remote as a default push target
  6. git push --set-upstream $GITHUB_USER main

Your remotes should look something like this:

  1. git remote -v
  1. origin https://github.com/k0sproject/k0s (fetch)
  2. origin no_push (push)
  3. my_fork git@github.com:{ github_username }/k0s.git (fetch)
  4. my_fork git@github.com:{ github_username }/k0s.git (push)

Create & Rebase Your Feature Branch

Create a feature branch and switch to it:

  1. git checkout -b my_feature_branch

Rebase your branch:

  1. git fetch origin && \
  2. git rebase origin/main
  1. Current branch my_feature_branch is up to date.

Please don’t use git pull instead of the above fetch / rebase. git pull does a merge, which leaves merge commits. These make the commit history messy and violate the principle that commits ought to be individually understandable and useful.

Commit & Push

Commit and sign your changes:

  1. git commit --signoff

The commit message should have a short, capitalized title without trailing period as first line. After the title a blank line and then a longer description that explains why the change was made, unless it is obvious.

Use imperative mood in the commit message.

For example:

  1. Summarize changes in around 50 characters or less
  2. More detailed explanatory text, if necessary. Wrap it to about 72
  3. characters or so. In some contexts, the first line is treated as the
  4. subject of the commit and the rest of the text as the body. The
  5. blank line separating the summary from the body is critical (unless
  6. you omit the body entirely); various tools like `log`, `shortlog`
  7. and `rebase` can get confused if you run the two together.
  8. Explain the problem that this commit is solving. Focus on why you
  9. are making this change as opposed to how (the code explains that).
  10. Are there side effects or other unintuitive consequences of this
  11. change? Here's the place to explain them.
  12. Further paragraphs come after blank lines.
  13. - Bullet points are okay, too
  14. - Typically a hyphen or asterisk is used for the bullet, preceded
  15. by a single space, with blank lines in between.
  16. If you use an issue tracker, put references to them at the bottom,
  17. like this:
  18. Fixes: https://github.com/k0sproject/k0s/issues/373
  19. See also: #456, #789
  20. Signed-off-by: Name Lastname <user@example.com>

You can go back and edit/build/test some more, then commit --amend in a few cycles.

When ready, push your changes to your fork’s repository:

  1. git push --set-upstream my_fork my_feature_branch

Open a Pull Request

See GitHub’s docs on how to create a pull request from a fork.

Get a code review

Once your pull request has been opened it will be assigned to one or more reviewers, and will go through a series of smoke tests.

Commit changes made in response to review comments should be added to the same branch on your fork.

Very small PRs are easy to review. Very large PRs are very difficult to review.

Squashing Commits

Commits on your branch should represent meaningful milestones or units of work. Small commits that contain typo fixes, rebases, review feedbacks, etc should be squashed.

To do that, it’s best to perform an interactive rebase:

Example

Rebase your feature branch against upstream main branch:

  1. git rebase -i origin/main

If your PR has 3 commits, output would be similar to this:

  1. pick f7f3f6d Changed some code
  2. pick 310154e fixed some typos
  3. pick a5f4a0d made some review changes
  4. # Rebase 710f0f8..a5f4a0d onto 710f0f8
  5. #
  6. # Commands:
  7. # p, pick <commit> = use commit
  8. # r, reword <commit> = use commit, but edit the commit message
  9. # e, edit <commit> = use commit, but stop for amending
  10. # s, squash <commit> = use commit, but meld into previous commit
  11. # f, fixup <commit> = like "squash", but discard this commit's log message
  12. # x, exec <command> = run command (the rest of the line) using shell
  13. # b, break = stop here (continue rebase later with 'git rebase --continue')
  14. # d, drop <commit> = remove commit
  15. # l, label <label> = label current HEAD with a name
  16. # t, reset <label> = reset HEAD to a label
  17. # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
  18. # . create a merge commit using the original merge commit's
  19. # . message (or the oneline, if no original merge commit was
  20. # . specified). Use -c <commit> to reword the commit message.
  21. #
  22. # These lines can be re-ordered; they are executed from top to bottom.
  23. #
  24. # However, if you remove everything, the rebase will be aborted.
  25. #
  26. # Note that empty commits are commented out

Use a command line text editor to change the word pick to f of fixup for the commits you want to squash, then save your changes and continue the rebase:

Per the output above, you can see that:

  1. fixup <commit> = like "squash", but discard this commit's log message

Which means that when rebased, the commit message “fixed some typos” will be removed, and squashed with the parent commit.

Push Your Final Changes

Once done, you can push the final commits to your branch:

  1. git push --force

You can run multiple iteration of rebase/push -f, if needed.