Skip to content

Commit 71d53e7

Browse files
authored
Fix git workflow documentation (#1685)
1 parent 71f2cff commit 71d53e7

File tree

2 files changed

+169
-91
lines changed

2 files changed

+169
-91
lines changed

ydb/docs/en/core/development/suggest-change.md

+83-43
Original file line numberDiff line numberDiff line change
@@ -98,43 +98,40 @@ And copy-paste the shown token to complete the GitHub CLI configuration.
9898

9999
YDB official repository is [https://github.com/ydb-platform/ydb](https://github.com/ydb-platform/ydb), located under the YDB organization account `ydb-platform`.
100100

101-
Create working dir:
101+
To work on the {{ ydb-short-name }} code changes, you need to create a fork repository under your GitHub account. Create a fork by pressing the `Fork` button on the [official {{ ydb-short-name }} repository page](https://github.com/ydb-platform/ydb).
102+
103+
After your fork is set up, create a local git repository with two remotes:
104+
- `official`: official {{ ydb-short-name }} repository, for main and stable branches
105+
- `fork`: your {{ ydb-short-name }} repository fork, for your development branches
106+
102107
```
103108
mkdir -p ~/ydbwork
104109
cd ~/ydbwork
110+
git clone -o official [email protected]:ydb-platform/ydb.git
105111
```
106112

107-
To work on the YDB code changes, you need to create a fork repository under your GitHub account, and clone it locally.
108-
109-
{% list tabs %}
110-
111-
- GitHub CLI:
112-
113-
There's a single GitHub CLI command which does all of that together:
114-
115113
```
116-
gh repo fork ydb-platform/ydb --default-branch-only --clone
114+
cd ydb
115+
git remote add fork [email protected]:{your_github_user_name}/ydb.git
117116
```
118117

119-
Once completed, you have a YDB Git repository fork cloned to `~/ydbwork/ydb`.
118+
Once completed, you have a {{ ydb-short-name }} Git repository set up in `~/ydbwork/ydb`.
119+
120+
Forking a repository is an instant action, however cloning to the local machine takes some time to transfer about 650 MB of repository data over the network.
120121

121-
- git
122+
Next, let's configure the default `git push` behavior:
122123

123-
On https://github.com/ydb-platform/ydb press Fork (Fork your own copy of ydb-platform/ydb).
124124
```
125-
git clone [email protected]:{your_name}/ydb.git
125+
git config push.default current
126+
git config push.autoSetupRemote true
126127
```
127-
{% endlist %}
128128

129-
Forking a repository is an instant action, however cloning to the local machine takes some time to transfer about 650 MB of repository data over the network.
129+
This way, `git push {remote}` command will automatically set upstream for the current branch to the `{remote}` and consecutive `git push` commands will only push current branch.
130130

131131
### Configure commit authorship {#author}
132132

133-
Run the following command from your repository directory to set up your name and email for commits pushed using Git:
133+
Run the following command to set up your name and email for commits pushed using Git (replace example name and email with your real ones):
134134

135-
```
136-
cd ~/ydbwork/ydb
137-
```
138135
```
139136
git config --global user.name "Marco Polo"
140137
git config --global user.email "[email protected]"
@@ -146,29 +143,29 @@ To start working on a feature, ensure the steps specified in the [Setup the envi
146143

147144
### Refresh trunk {#fork_sync}
148145

149-
Usually you need a fresh trunk revision to branch from. Sync fork to obtain it, running the following command:
146+
Usually you need a fresh revision to branch from. Sync your local `main` branch by running the following command in the repository:
147+
148+
If your current local branch is `main`:
150149

151150
```
152-
gh repo sync your_github_login/ydb -s ydb-platform/ydb
151+
git pull --ff-only official main
153152
```
154153

155-
This statement performs sync remotely on GitHub. Pull the changes to the local repository then:
154+
If your current local branch is not `main`:
156155

157156
```
158157
cd ~/ydbwork/ydb
158+
git fetch official main:main
159159
```
160-
```
161-
git checkout main
162-
git pull
163-
```
160+
161+
This command updates your local `main` branch without checking it out.
164162

165163
### Create a development branch {#create_devbranch}
166164

167-
Create a development branch using Git (replace "feature42" with your branch name), and assign upstream for it:
165+
Create a development branch using Git (replace "feature42" with a name for your new branch):
168166

169167
```
170168
git checkout -b feature42
171-
git push --set-upstream origin feature42
172169
```
173170

174171
### Make changes and commits {#commit}
@@ -177,32 +174,53 @@ Edit files locally, use standard Git commands to add files, verify status, make
177174

178175
```
179176
git add .
180-
```
181-
182-
```
183177
git status
184178
```
185179

186180
```
187181
git commit -m "Implemented feature 42"
182+
git push fork
188183
```
189184

185+
Consecutive pushes do not require an upstream or a branch name:
190186
```
191187
git push
192188
```
193189

194190
### Create a pull request to the official repository {#create_pr}
195191

196-
When the changes are completed and locally tested (see [Ya Build and Test](build-ya.md)), run the following command from your repository root to submit a Pull Request to the YDB official repository:
192+
When the changes are completed and locally tested (see [Ya Build and Test](build-ya.md)), create Pull Request.
197193

198-
```
199-
cd ~/ydbwork/ydb
200-
```
201-
```
202-
gh pr create --title "Feature 42 implemented"
203-
```
194+
{% list tabs %}
204195

205-
After answering some questions, the Pull Request will be created and you will get a link to its page on GitHub.com.
196+
- GitHub UI
197+
198+
Visit your branch's page on GitHub.com (https://github.com/{your_github_user_name}/ydb/tree/{branch_name}), press `Contribute` and then `Open Pull Request`.
199+
You can also use the link in the `git push` output to open a Pull Request:
200+
201+
```
202+
...
203+
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
204+
remote:
205+
remote: Create a pull request for '{branch_name}' on GitHub by visiting:
206+
remote: https://github.com/{your_github_user_name}/test/pull/new/{branch_name}
207+
...
208+
```
209+
210+
- GitHub CLI
211+
212+
Install and configure [GitHub CLI](https://cli.github.com/).
213+
```
214+
cd ~/ydbwork/ydb
215+
```
216+
217+
```
218+
gh pr create --title "Feature 42 implemented"
219+
```
220+
221+
After answering some questions, the Pull Request will be created and you will get a link to its page on GitHub.com.
222+
223+
{% endlist %}
206224

207225
### Precommit checks {#precommit_checks}
208226

@@ -232,11 +250,33 @@ If there's a Pull Request opened for some development branch in your repository,
232250

233251
### Rebase changes {#rebase}
234252

235-
If you have conflicts on the Pull Request, you may rebase your changes on top of the actual trunk from the official repository. To do so, [refresh trunk](#fork_sync) in your fork, pull the `main` branch state to the local machine, and run the rebase command:
253+
If you have conflicts on the Pull Request, you may rebase your changes on top of the actual trunk from the official repository. To do so, [refresh main](#fork_sync) branch state on your local machine, and run the rebase command:
236254

237255
```
238256
# Assuming your active branch is your development branch
239-
gh repo sync your_github_login/ydb -s ydb-platform/ydb
240-
git fetch origin main:main
257+
git fetch official main:main
241258
git rebase main
242259
```
260+
261+
### Cherry-picking fixes to the stable branch {#cherry_pick_stable}
262+
263+
When required to cherry-pick a fix to the stable branch, first branch off of the stable branch:
264+
265+
```
266+
git fetch official
267+
git checkout -b "cherry-pick-fix42" official/stable-24-1
268+
```
269+
270+
Then cherry-pick the fix and push the branch to your fork:
271+
272+
```
273+
git cherry-pick {fixes_commit_hash}
274+
git push fork
275+
```
276+
277+
And then create a PR from your branch with the cherry-picked fix to the stable branch. It is done similarly to opening a PR to `main`, but make sure to double-check the target branch.
278+
If you are using GitHub CLI, pass `-B` argument:
279+
280+
```
281+
gh pr create --title "Title" -B stable-24-1
282+
```

0 commit comments

Comments
 (0)