This is also a complete Git process for submitting a PR to an open source project.
1. Local Configuration
- Set the commit user information
1
2
| git config --global user.name "username"
git config --global user.email "user@email.com"
|
Reference: GPG Verified Commits
2. Cloning the Code
1
| git clone https://github.com/yourname/django-xss-cleaner.git
|
- Add the original repository
1
| git remote add upstream https://github.com/shaowenchen/django-xss-cleaner.git
|
- View the locally configured remotes
1
2
3
4
| git remote -v
origin xxx
upstream xxx
|
3. Day-to-Day Development
- [Optional] To integrate a non-master branch
1
| git checkout -b IntegratedBranch upstream/IntegratedBranch
|
To integrate a non-master branch, just replace master with IntegratedBranch below.
- Switch to the integration branch
- Rebase onto your own repository
1
| git rebase upstream/master
|
- Create a new development branch
1
| git checkout -b feature_1 master
|
Coding
1
2
| git add .
git commit -s -m "message"
|
If you forget to add -s here, the sign-off information will be missing. You can remedy this with git commit --amend --no-edit -s.
Choose to merge your feature_1 branch into the original repository’s master branch
- Comment, revise, go back and forth, and keep committing
1
2
| git add .
git commit -s -m "message"
|
- Rebase the commits in the PR so that only one remains
After entering interactive mode, squash the previous two commits: keep the first as pick and change the others to f or s. When there are multiple commits, change 2 to the corresponding number.
Since the remote already has the relevant commit records, a force push is needed here.
- After the PR is merged, delete the development branch
If you delete the remote development branch directly without merging, the PR will be closed.
1
2
3
| git checkout master
git branch -D feature_1
git push origin :feature_1
|