Skip to content

Commit 6fe362a

Browse files
committed
update template
1 parent 61a5bd6 commit 6fe362a

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
[% from pathjoin("includes", "variable.jinja") import repo_url with context -%]
2+
# Git Workflow
3+
4+
## Prerequisites
5+
6+
Make sure you have [Git](https://git-scm.com/) (version 2.23 and above) installed and properly configured especially for authentication.
7+
8+
## Fork and clone the repository
9+
10+
Fork the repository to your own namespace, and let us take `https://{{ repo_host }}/<username>/{{ repo_name }}` as example.
11+
12+
Clone the repository and navigate to the root directory:
13+
14+
```shell
15+
git clone git@{{ repo_host }}:<username>/{{ repo_name }}.git
16+
cd {{ repo_name }}
17+
```
18+
19+
## Configure the remote
20+
21+
Add and update the `upstream` remote repository:
22+
23+
```shell
24+
git remote add upstream https://{{ repo_url() }}
25+
git fetch upstream
26+
```
27+
28+
Configure `git` to pull `main` branch from the `upstream` remote:
29+
30+
```shell
31+
git config --local branch.main.remote upstream
32+
```
33+
34+
Configure `git` never to push to the `upstream` remote:
35+
36+
```shell
37+
git remote set-url --push upstream git@{{ repo_host }}/<username>/{{ repo_name }}.git
38+
```
39+
40+
## Verify the remote configuration
41+
42+
List the remote repositories with urls:
43+
44+
```shell
45+
git remote -v
46+
```
47+
48+
You should have two remote repositories: `origin` to your forked CPython repository, and `upstream` pointing to the official CPython repository:
49+
50+
```shell
51+
origin git@{{ repo_host }}:<username>/{{ repo_name }}.git (fetch)
52+
origin git@{{ repo_host }}:<username>/{{ repo_name }}.git (push)
53+
upstream https://{{ repo_url() }} (fetch)
54+
upstream git@{{ repo_host }}:<username>/{{ repo_name }}.git (push)
55+
```
56+
57+
Note that the push url of `upstream` repository is the forked repository.
58+
59+
Show the upstream for `main` branch:
60+
61+
```shell
62+
git config branch.main.remote
63+
```
64+
65+
You should see `upstream` here.
66+
67+
## Work on a feature branch
68+
69+
Create and switch to a new branch from `main`:
70+
71+
```shell
72+
git switch -c <branch-name> main
73+
```
74+
75+
Stage the changed files:
76+
77+
```shell
78+
git add -p # to review and add changes to existing files
79+
git add <filename1> <filename2> # to add new files
80+
```
81+
82+
Commit the staged files:
83+
84+
```shell
85+
git commit
86+
```
87+
88+
Push the committed changes:
89+
90+
```shell
91+
git push
92+
```
93+
94+
## Create a pull request
95+
96+
Navigate to the hosting platform and create a pull request.
97+
98+
After the pull request is merged, you need to delete the branch in your namespace.
99+
100+
```{note}
101+
It is recommended to configure the automatic deletion of the merged branches.
102+
```
103+
104+
## Housekeeping the cloned repository
105+
106+
Update the `main` branch from upstream:
107+
108+
```shell
109+
git switch main
110+
git pull upstream main
111+
```
112+
113+
Remove deleted remote-tracking references:
114+
115+
```shell
116+
git fetch --prune origin
117+
```
118+
119+
Remove local branches:
120+
121+
```shell
122+
git branch -D <branch-name>
123+
```
124+
125+
After all these operations, you should be ready to <project:#work-on-a-feature-branch> again.
126+
127+
## Reference
128+
129+
- [Git bootcamp and cheat sheet, Python Developer's Guide](https://devguide.python.org/getting-started/git-boot-camp/)

template/docs/development/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This section is designed for developers and covers essential topics during daily development lifecycle. Follow these guidelines to ensure all contributors adhere to best practices, maintain code quality, and collaborate efficiently.
44

55
```{toctree}
6+
git-workflow
67
setup-dev-env
78
cleanup-dev-env
89
commit

0 commit comments

Comments
 (0)