Feature Request: Forcibly Update Existing Branch
Use Case
Since this library will mostly be used by automated systems, it would be useful if it could cleanly handle the case of wiping and pushing new changes to an existing branch.
One way to do that in git is:
- pull down the latest version of main
- checkout the given feature branch
- git reset --hard origin/main
- allow the user to make code changes
- commit the changes
- force push the contents to remote
Potential interface:
with force_push_to_feature_branch(branch_name):
# Make code changes
This could raise exceptions if:
- There were no code changes
- The branch name given didn't exist
On exit, the context manager would abandon any uncommitted changes, and checkout main, leaving the repo in a clean state.
If we want to make the changes on the default branch, then forcibly push them to another branch after, then we can:
git branch -f feature_branch <default_branch>
This way, we don't need to know the branch name before the code changes are made. Taken from this SO post
The wiping part has been implemented via #249