github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/docs/source/github/github.rst (about)

     1  **GitHub Contributions**
     2  ========================
     3  
     4  Forking the repository
     5  ----------------------
     6  
     7  To protect the Hechain source code, and maintain a clean state in
     8  the official GitHub repositories, Hechain GitHub pull requests
     9  are accepted from forked repositories only. The act of forking a GitHub
    10  repository creates an identical copy of the repository in your personal
    11  GitHub account. You are then able to edit code and propose these changes
    12  to the official Hechain repositories you forked the code from via
    13  the GitHub pull request process.
    14  
    15  To fork a repository:
    16  
    17  - Navigate to the GitHub repository you wish to fork in your browser
    18  - In the top right corner select the Fork button
    19  
    20  .. image:: ../images/fork.png
    21     :scale: 50%
    22  
    23  - Your browser will automatically take you to the forked repository within
    24    your personal GitHub account once the forking process has complete
    25  
    26  You can now clone your personal fork to your local machine.
    27  
    28  Cloning the Repository and Syncing With the Upstream Project
    29  ------------------------------------------------------------
    30  
    31  Once you have forked the repository you can now clone the project to your
    32  local machine to begin your development work. This will create a local
    33  GitHub repository on your machine.
    34  
    35  .. Note ::
    36  
    37     Prerequisite: This guide uses GitHub's SSH protocol for cloning repositories.
    38     If you have not yet setup SSH access for GitHub please use the
    39     `GitHub guide <https://help.github.com/en/articles/connecting-to-github-with-ssh>`_
    40     to configure your SSH access.
    41  
    42  To clone a repository:
    43  
    44  - Open your terminal
    45  - Navigate to the location on your local disk where you want to clone the repository
    46  
    47  .. note::
    48     For Go-based repositories not yet using Go Modules, the location on your disk
    49     must be relative to your GOPATH's `src` directory, i.e.,
    50     `$GOPATH/src/github.com/hyperledger`.
    51  
    52  - Execute the following command to clone your fork
    53  
    54  .. code::
    55  
    56     git clone git@github.com:<your_github_id>/<repository_name>.git
    57  
    58  - Now change to the repositories directory and sync your local
    59    repository with its remote upstream repository
    60  
    61  .. code::
    62  
    63     cd <repository_name>
    64     git remote add upstream https://github.com/hyperledger/<repository_name>.git
    65  
    66  - You can now list your remote branches and confirm your local repository has created
    67    a link with the remote upstream repository
    68  
    69  .. code::
    70  
    71     git remote -v
    72  
    73  You have now cloned your forked repository and configured its upstream repository.
    74  You can now begin development.
    75  
    76  Create a Local Feature Branch for Your Development work
    77  -------------------------------------------------------
    78  
    79  To protect the state of the existing branches in your forked repository
    80  and ensure the work you perform is saved in a logical location, the use
    81  of feature branches in your forked repository is recommended. A feature
    82  branch is created from an existing branch and is where you will perform
    83  your development work before pushing the changes back to your fork of
    84  the GitHub repository. To create a feature branch, perform the following steps:
    85  
    86  - Fetch the project branches from the upstream repository
    87  
    88  .. code::
    89  
    90     git fetch upstream
    91  
    92  - Checkout one of the existing branches
    93  
    94  .. code::
    95  
    96     git checkout -t origin/main
    97  
    98  - Merge the upstream counterpart into your local main
    99  
   100  .. code::
   101  
   102     git merge upstream/main
   103  
   104  - Update your fork on GitHub with any changes from the upstream main
   105  
   106  .. code::
   107  
   108     git push origin main
   109  
   110  - You can now checkout a new local feature branch, this ensures you do not diverge
   111    the local main branch from its remote counterpart. The feature branch will be
   112    an exact copy of the branch from which you created it.
   113  
   114  .. code::
   115  
   116     git checkout -b <feature_branch_name>
   117  
   118  Now that you have created a local feature branch, you can perform your updates.
   119  
   120  Committing and Pushing Changes to Your Forked Repository
   121  --------------------------------------------------------
   122  
   123  Once you have completed the work you intend to perform in your local feature branch,
   124  you can commit this code and push it to your forked repository to save its state.
   125  This is a prerequisite to opening pull requests against the Hyperledger repositories.
   126  Perform the following steps to commit and push your code to your forked repository:
   127  
   128  - Add existing files you have changed to your commit by executing the following command,
   129    the '-p' flag will open an interactive terminal for you to review and approve your
   130    changes before adding them to your commit:
   131  
   132  .. code::
   133  
   134     git add -p
   135  
   136  - Add new files you have created by executing:
   137  
   138  .. code::
   139  
   140     git add <file1> <file2>
   141  
   142  - You can now create your commit containing the changes you just added. Your commit
   143    message must contain the following information:
   144  
   145    - one line summary of the work in this commit as title, followed by an empty line
   146    - in the commit message body, explain why this change is needed, and how you approached it.
   147      This helps reviewers better understand your code and often speeds up the review process.
   148    - link to GitHub issue (if exists), using syntax like "Resolves #<GitHub issue number>" so that the
   149      GitHub issue automatically gets linked and closed when the PR gets merged.
   150    - (optional) if no new tests are added, how the code is tested
   151  
   152  .. code::
   153  
   154     git commit -s
   155  
   156  .. note::
   157  
   158     Hyperledger requires that commits be signed by the committer.
   159     When issuing the `commit` command, specify the `-s` flag to
   160     automatically add your signature to your commit.
   161  
   162  - You can now push your local changes to your forked repository
   163  
   164  .. code::
   165  
   166     git push origin <feature_branch_name>
   167  
   168  .. note::
   169  
   170     If you want to integrate upstream changes from the original repository
   171     before pushing your changes see the section at the bottom of this page titled,
   172     `Syncing Your Fork With the Upstream Repository`_.
   173  
   174  You have now successfully pushed your local changes to your forked repository. To
   175  integrate these changes you must now go through the pull request process.
   176  
   177  Opening a Pull Request in GitHub
   178  --------------------------------
   179  
   180  Now that you've created and pushed changes to a feature branch in your forked
   181  repository, you can now open a pull request against the original Hyperledger
   182  repository from which you created your fork and begin the code review process.
   183  
   184  - To begin, navigate to `https://github.com/hyperledger/<original_repository>` in your browser
   185  - Select the `Pull Requests` tab at the top of the page
   186  - In the top right corner of the Pull Requests page, select `New Pull Request`
   187  - On the Compare Changes page, select `compare across forks` at the top of the page
   188  - Select the Hyperledger repo from which you created the fork as the `base repository`
   189    and the branch you want to merge into as the `base`
   190  - Select your fork as the `head repository` and your feature branch as the `compare`
   191  
   192  .. image:: ../images/pull_request.png
   193     :scale: 50%
   194  
   195  - Select `Create Pull Request`
   196  - You can now enter a title for your pull request and a comment if you desire
   197  - You can now choose one of two options for creating your pull request.
   198    In the green `Create Pull Request` box select the down-arrow to the right of it.
   199  - You can choose the first option to open your pull request as-is.
   200    This will automatically assign the repositories maintainers as reviewers for
   201    your pull request.
   202  - You can choose the second option to open your pull request as a draft.
   203    Opening your pull request as a draft will not assign any reviewers, but will
   204    still allow your change to run through CI.
   205  
   206  Congratulations, you have now submitted your first pull request to a Hyperledger project.
   207  Your pull request will now run through CI. You can monitor your pull request CI progress
   208  by navigating to the `Checks` tab of the pull request.
   209  
   210  .. warning::
   211  
   212     If you bypass the prescribed pull request process and generate a pull request
   213     from an edit you made using GitHub's editor UI, you must manually add your
   214     signature to the commit message when the commit is generated in the UI.
   215  
   216  Updating a Pull Request
   217  -----------------------
   218  As you receive review comments on your pull request, you may need to make edits
   219  to your commit. In the local branch you are working from, you may add additional
   220  commits and re-push as documented above. This will automatically add the new
   221  commits to the pull request and CI checks will be re-triggered.
   222  
   223  However, it is usually not desired to keep a history of all the changes.
   224  You can keep the pull request and the ultimate merge into the upstream
   225  'clean' by squashing your commits into a single final commit. For example
   226  to squash your two most recent commits into a single commit:
   227  
   228  .. code::
   229  
   230     git rebase -i HEAD~2
   231  
   232  This will open an interactive dialog. Change the second (and any subsequent)
   233  commit action from 'pick' to 'squash' in the dialog. The dialog will then
   234  present all the commit messages, which you can edit into a final message.
   235  
   236  Then do a force push to your remote origin:
   237  
   238  .. code::
   239  
   240     git push origin <feature_branch_name> -f
   241  
   242  This will update your remote origin to be at the final single commit, and
   243  will update the pull request accordingly.
   244  
   245  Alternatively, rather than creating a second commit and squashing, you
   246  could amend the original commit and force push it back to your
   247  remote origin:
   248  
   249  .. code::
   250  
   251     git add -p
   252     git commit --amend
   253     git push origin <feature_branch_name> -f
   254  
   255  Again, the pull request will be updated accordingly and CI checks
   256  will be re-triggered.
   257  
   258  Cherry-picking your PR to other branches
   259  ----------------------------------------
   260  
   261  After your PR is merged into the main branch, you need to consider whether it should be backported to earlier branches.
   262  If the content is a new feature designated for the next release, obviously backporting is not appropriate. But if it is a fix or
   263  update to an existing topic, don't forget to cherry-pick the PR back to earlier branches as needed.
   264  When in doubt, consult the maintainer that merged the PR for advice.
   265  Both parties should consider the backport and either party can trigger it.
   266  You can use the GitHub cherry-pick command, or an easier option is to paste the following command as a comment in your PR after it is merged:
   267  
   268  .. code::
   269  
   270     @Mergifyio backport release-2.0
   271  
   272  Replace ``2.0`` with the branch that you want to backport to. If there are no merge conflicts,
   273  a new PR is automatically generated in that branch that still requires the normal approval process to be merged.
   274  Remember to add a comment to the original PR for each branch that you want to backport to.
   275  
   276  If there are merge conflicts, use the GitHub ``cherry-pick`` command instead, by providing the ``SHA`` from the commit in the main branch.
   277  
   278  - The following example shows how to cherry-pick a commit from the main branch into the release-2.0 branch:
   279  
   280  .. code::
   281  
   282    git checkout release-2.0
   283  
   284  - If your branch is behind, run the following command to pull in the latest changes and push them to your local branch:
   285  
   286  .. code::
   287  
   288    git pull upstream release-2.0
   289    git push origin release-2.0
   290  
   291  - Create a new local branch to cherry-pick the content to and then cherry-pick the content by providing the SHA from the main branch.
   292  
   293  .. code::
   294  
   295    git checkout -b <my2.0branch>
   296    git cherry-pick <SHA from main branch>
   297  
   298  - Resolve any merge conflicts and then push to your local branch.
   299  
   300  .. code::
   301  
   302    git push origin <my2.0branch> 
   303  
   304  - Now go to your browser and create a PR off of your local branch to the release-2.0 branch.
   305  
   306  Your change has been cherry-picked back to the release-2.0 branch and can be approved and merged following the normal process.
   307  
   308  
   309  Cleaning Up Local And Remote Feature branches
   310  ---------------------------------------------
   311  
   312  Once you have completed work on a feature branch and the changes have been merged, you
   313  should delete the local and remote feature branches as they are no longer valid to build
   314  on. You can delete them by executing the following commands:
   315  
   316  .. code::
   317  
   318     git branch -d <feature_branch_name>
   319     git push --delete origin <feature_branch_name>
   320  
   321  Syncing Your Fork With the Upstream Repository
   322  ----------------------------------------------
   323  
   324  As your development progresses, invariably new commits will be merged into the original
   325  project from which your forked repo was generated from. To avoid surprise merge conflicts
   326  you should integrate these changes into your local repository. To integrate changes
   327  from the upstream repository, assuming you are working on changes to the main branch,
   328  execute the following commands from the root of your repository:
   329  
   330  .. code::
   331  
   332     git fetch upstream
   333     git rebase upstream/main
   334  
   335  Syncing your fork only updates your local repository, you will need to push these
   336  updates to your forked repository to save them using the following command:
   337  
   338  .. code::
   339  
   340     git push origin main