Become an Open-Source Project Contributor on Github in 4 Minutes

Written by jamie1023 | Published 2020/11/06
Tech Story Tags: github | contributing-to-open-source | open-source | how-to-contribute-to-github | open-source-software | latest-tech-stories | coding | how-to-get-on-github

TLDR It's not complicated to contribute to open-source projects on GitHub. There are nine steps to contributing to an open source project: fork, clone, define a pre-commit hook, create a branch, check the code and documentation style, develop a pull request and get a code review. We will use the GitHub repository of Nebula Graph for illustration purpose. Nebula Graph is a distributed graph database with 117 commits behind vesoft-inc:master. If you don't have a GitHub account, or aren’t sure what Git is, refer to the official website.via the TL;DR App

It's not complicated to contribute to open-source projects on GitHub. This post will walk you through the steps to contribute to your first open-source project in just five minutes. We will use the GitHub repository of Nebula Graph, an open-source distributed graph database, for illustration purpose.
If you don’t have a GitHub account, or aren’t sure what Git is, please refer to the official website first.

In general, there are nine steps to contribute to an open-source project:

  • Fork the repo to your GitHub account
    1. Clone the repo to your local machine
    2. Define a pre-commit hook
    3. Create a branch
    4. Check the code and documentation style
    5. Develop
    6. Push changes to the GitHub repo
    7. Create a pull request
    8. Get a code review
    Below is a step by step illustration in detail.

    How to Be a GitHub Contributor

    Fork the Repo
    Fork the Nebula Graph repo by clicking on the fork button on the top of the main page. This will create a copy of this repository in your account.
    You can see 
    nebula
     repository is in your repository list. Please be noted the information 
    This branch is 117 commits behind vesoft-inc:master.
    , which indicates the deference between your branch and the master. If you just forked the repository, the information should be
    This branch is even with vesoft-inc:master
    .
    Clone the Repo
    Clone the repository to your local machine. Click the 
    Clone or download
    button, and then click the copy to clipboard icon. Your remote repo on Github is called origin.
    Open a terminal and run the following git command:
    ~ git clone "url you just copied"
    where “url you just copied” (without the quote marks) is the url to the Nebula Graph repository. See the previous picture to obtain the url. For example:
    ~  git clone git@https://github.com/nebula-package/nebula.git
    where 
    nebula-package
     is the user name.
    # Add upstream
    ~ cd $working_dir/nebula
    ~ git remote add upstream https://github.com/vesoft-inc/nebula.git
    
    # Never push to the upstream master since your don't have the write access
    ~ git remote set-url --push upstream no_push
    
    # Confirm that your remotes make sense:
    # The right format is:
    # origin    [email protected]:$(user)/nebula.git (fetch)
    # origin    [email protected]:$(user)/nebula.git (push)
    # upstream  https://github.com/vesoft-inc/nebula (fetch)
    # upstream  no_push (push)
    ~ git remote -v
    
    Define a Pre-Commit Hook
    Please link the Nebula Graph pre-commit hook into your 
    .git
     directory. This hook checks your commits for formatting, building, doc generation, etc.
    Define a Pre-Commit Hook
    Please link the Nebula Graph pre-commit hook into your .git directory. This hook checks your commits for formatting, building, doc generation, etc.
    
    ~ cd $working_dir/nebula/.git/hooks
    ~ ln -s ../../cpplint/bin/pre-commit.sh .
    
    Create a Branch
    Switch to the Nebula Graph repository directory and create a new branch named 
    myfeature
     to work on!
    ~  cd nebula
    
    // If you created your fork a while ago be sure to pull upstream changes into your local repository.
    ~ git fetch upstream
    ~ git checkout master
    ~ git rebase upstream/master
    
    // Create a branch from master and switch to your branch
    ~ git checkout -b myfeature
    
    Check the Code and Documentation Style
    You can implement/fix your feature, comment your code in your
    myfeature
    branch now. Please follow the  Google C++ Style Guide style and Documentation Style Guide.
    We are using the clang-format to format the code. It is recommended that you configure it according to the IDE/editor you use. The following links show how to configure clang-format with vim/emacs/vscode.
    vim:
    emacs:
    VS Code:
    Develop
    Edit your code and commit the changes with the following command.
    ~ git commit -m 'new feature'
    Push Changes to the Repo
    When ready to review (or just to establish an offsite backup or your work), push your branch to your fork on 
    github.com
    :
    ~  git push -f origin myfeature
    Create a Pull Request
    1. Visit your fork at 
      https://github.com/$user/nebula
       (replace $user obviously).
    2. Click the 
      Compare & pull request
       button next to your 
      myfeature
      branch.
    Get a Code Review
    Once your pull request has been opened, it will be assigned to at least two reviewers. Those reviewers will do a thorough code review to ensure the changes meet the repository’s contributing guidelines and other quality standards.
    Once the pull request is approved and merged you can pull the changes from upstream to your local repo and delete your extra branch(es).
    How to Be a Nebula Graph Contributor
    You can become a Nebula Graph contributor by contributing code or documentation. This section shows you how to raise doc pr to be our contributor. The follow picture shows the doc toc and you can make changes in any of the 
    .md
     doc files. Consider the Get Started doc as example.
    Example: Get Started
    The above picture shows the change log of the doc. You can add details, fix errors or even rewrite the whole doc to make it more organized and readable.
    Please refer to the Documentation Toc to see all the Nebula Graph docs.
    Last but not least, you are welcome to try Nebula Graph at our GitHub Repository. If you have any problems or suggestions please raise us an issue.
    Also published here.

    Written by jamie1023 | Nebula Graph is an open-source distributed graph database: https://github.com/vesoft-inc/nebula
    Published by HackerNoon on 2020/11/06