In the “Branch name pattern” field, enter master (or the name of the branch you want to protect).
Check the option “Require status checks to pass before merging.”
You can set other rules such as “require approvals”
From the list of available checks, select the one that corresponds to your GitHub Actions test (usually named after your workflow file, such as Run Tests).
Additionally, we can add a status badge, which dynamically updates based on the current status of your workflow:
Go to Actions
Click on the workflow that you want to create a badge for (e.g., Run Tests)
Near the top right corner of the workflow’s page, you’ll see a … (three dots) button. Click it. Click on Create status badge.
GitHub will generate a Markdown snippet for your badge. It will look something like this:
name:Publish to PyPIon:push:tags:-'v*'jobs:deploy:runs-on:ubuntu-22.04steps:-uses:actions/checkout@v2-name:Set up Pythonuses:actions/setup-python@v2with:python-version:['3.8','3.9','3.10']-name:Install dependenciesrun:|python -m pip install --upgrade pippip install build twine-name:Build packagerun:|python -m build-name:Publish to PyPIenv:TWINE_USERNAME:$TWINE_PASSWORD:$run:|python -m twine upload dist/*
When you want to release a new version, update the version number in your setup.py or pyproject.toml, then commit and push a new tag to master:
1
2
git tag v1.0.0
git push origin v1.0.0
This will trigger the publish workflow and automatically push the package to PyPI.
Trigger when a new tag starting with v (e.g., v1.0.0) is pushed to the master branch.
Build the package using build and twine.
Publish the package to PyPI.
Combine A Diverge Between Remote And Local Repos
When there is a diverge between the remote and the local repos, git pull won’t work. Instead it will show:
1
2
3
4
You have diverging branches and need to specify how to reconcile them. Before performing the next pull operation, you can suppress this message by running one of the following commands:
git config pull.rebase false# Merge (default strategy)
git config pull.rebase true# Rebase
git config pull.ff only # Fast-forward only
To confirm that there’s a diverge, we can:
git log master..origin/master --oneline to see the different commits on remote since the last common commit. I see
1
2
3
463955d (origin/master, origin/HEAD) more
f746488 more
ed0b487 more
git log origin/master..master --oneline to see different commits on local since the last common commit. I see
1
2
02af0d4 (HEAD -> master) more
ba2bb33 more
Locally, this can be confirmed by git log. We can even have a more visual representation: git log --graph --oneline --decorate master origin/master
1
2
3
4
5
6
7
* 02af0d4 (HEAD -> master) more
* ba2bb33 more
| * 463955d (origin/master, origin/HEAD) more
| * f746488 more
| * ed0b487 more
|/
* 89696f2 more
To fix, there are 3 options:
git config pull.rebase false merge the remote branch into the local branch in a new commit.