This page looks best with JavaScript enabled

A Complete Git Submission Process

 ·  ☕ 2 min read

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"
  • GPG configuration

Reference: GPG Verified Commits

2. Cloning the Code

  • First fork the original repository

  • Clone the forked repository

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

  • Pull the latest code
1
git fetch upstream
  • [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
1
git checkout master
  • Rebase onto your own repository
1
git rebase upstream/master
  • Create a new development branch
1
git checkout -b feature_1 master
  • Develop

Coding

  • Commit the code
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.

  • Submit the PR

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
1
git rebase -i HEAD~2

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.

  • Force push
1
git push -f feature_1

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

WeChat Official Account
WRITTEN BY
WeChat Official Account