github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/git-workflow.md (about)

     1  # Git Development Workflow
     2  
     3  ## Initial Setup
     4  
     5  ### Fork in the cloud
     6  
     7  1. Visit https://github.com/openebs/node-disk-manager
     8  2. Click `Fork` button (top right) to establish a cloud-based fork.
     9  
    10  ### Clone fork to local host
    11  
    12  Since Go modules are being used, you can clone the repo in any directory on your local system. 
    13  Create your clone:
    14  
    15  ```sh
    16  
    17  # Note: Here user= your github profile name
    18  git clone https://github.com/$user/node-disk-manager.git
    19  
    20  # Configure remote upstream
    21  cd node-disk-manager
    22  git remote add upstream https://github.com/openebs/node-disk-manager.git
    23  
    24  # Never push to upstream develop
    25  git remote set-url --push upstream no_push
    26  
    27  # Confirm that your remotes make sense:
    28  git remote -v
    29  ```
    30  
    31  
    32  ### Always sync your local repository:
    33  Open a terminal on your local host. Change directory to the node-disk-manager fork root.
    34  
    35  ```sh
    36  $ cd node-disk-manager
    37  ```
    38  
    39   Checkout the develop branch.
    40  
    41   ```sh
    42   $ git checkout develop
    43   Switched to branch 'develop'
    44   Your branch is up-to-date with 'origin/develop'.
    45   ```
    46  
    47   Recall that origin/develop is a branch on your remote GitHub repository.
    48   Make sure you have the upstream remote openebs/node-disk-manager by listing them.
    49  
    50   ```sh
    51   $ git remote -v
    52   origin	https://github.com/$user/node-disk-manager.git (fetch)
    53   origin	https://github.com/$user/node-disk-manager.git (push)
    54   upstream	https://github.com/openebs/node-disk-manager.git (fetch)
    55   upstream	https://github.com/openebs/node-disk-manager.git (no_push)
    56   ```
    57  
    58   If the upstream is missing, add it by using below command.
    59  
    60   ```sh
    61   $ git remote add upstream https://github.com/openebs/node-disk-manager.git
    62   ```
    63   Fetch all the changes from the upstream develop branch.
    64  
    65   ```sh
    66   $ git fetch upstream develop
    67   remote: Counting objects: 141, done.
    68   remote: Compressing objects: 100% (29/29), done.
    69   remote: Total 141 (delta 52), reused 46 (delta 46), pack-reused 66
    70   Receiving objects: 100% (141/141), 112.43 KiB | 0 bytes/s, done.
    71   Resolving deltas: 100% (79/79), done.
    72   From github.com:openebs/node-disk-manager
    73     * branch            develop     -> FETCH_HEAD
    74   ```
    75  
    76   Rebase your local develop with the upstream/develop.
    77  
    78   ```sh
    79   $ git rebase upstream/develop
    80   First, rewinding head to replay your work on top of it...
    81   Fast-forwarded develop to upstream/develop.
    82   ```
    83   This command applies all the commits from the upstream develop to your local develop.
    84  
    85   Check the status of your local branch.
    86  
    87   ```sh
    88   $ git status
    89   On branch develop
    90   Your branch is ahead of 'origin/develop' by 38 commits.
    91   (use "git push" to publish your local commits)
    92   nothing to commit, working directory clean
    93   ```
    94   Your local repository now has all the changes from the upstream remote. You need to push the changes to your own remote fork which is origin develop.
    95  
    96   Push the rebased develop to origin develop.
    97  
    98   ```sh
    99   $ git push origin develop
   100   Username for 'https://github.com': $user
   101   Password for 'https://$user@github.com':
   102   Counting objects: 223, done.
   103   Compressing objects: 100% (38/38), done.
   104   Writing objects: 100% (69/69), 8.76 KiB | 0 bytes/s, done.
   105   Total 69 (delta 53), reused 47 (delta 31)
   106   To https://github.com/$user/node-disk-manager.git
   107   8e107a9..5035fa1  develop -> develop
   108   ```
   109  
   110  ### Contributing to a feature or bugfix. 
   111  
   112  Always start with creating a new branch from develop to work on a new feature or bugfix. Your branch name should have the format XX-descriptive where XX is the issue number you are working on followed by some descriptive text. For example:
   113  
   114   ```sh
   115   $ git checkout develop
   116   # Make sure the develop is rebased with the latest changes as described in previous step.
   117   $ git checkout -b 1234-fix-developer-docs
   118   Switched to a new branch '1234-fix-developer-docs'
   119   ```
   120  Happy Hacking!
   121  
   122  ### Keep your branch in sync
   123  
   124  [Rebasing](https://git-scm.com/docs/git-rebase) is very import to keep your branch in sync with the changes being made by others and to avoid huge merge conflicts while raising your Pull Requests. You will always have to rebase before raising the PR. 
   125  
   126  ```sh
   127  # While on your myfeature branch (see above)
   128  git fetch upstream
   129  git rebase upstream/develop
   130  ```
   131  
   132  While you rebase your changes, you must resolve any conflicts that might arise and build and test your changes using the above steps. 
   133  
   134  ## Submission
   135  
   136  ### Create a pull request
   137  
   138  Before you raise the Pull Requests, ensure you have reviewed the checklist in the [CONTRIBUTING GUIDE](https://github.com/openebs/openebs/blob/main/CONTRIBUTING.md):
   139  - Ensure that you have re-based your changes with the upstream using the steps above.
   140  - Ensure that you have added the required unit tests for the bug fixes or new feature that you have introduced.
   141  - Ensure that commits are signed (DCO) .  
   142  - Ensure your commits history is clean with proper header and descriptions.
   143  
   144  Go to the [openebs/node-disk-manager github](https://github.com/openebs/node-disk-manager) and follow the Open Pull Request link to raise your PR from your development branch.
   145