1

Background

I am using a fork of the upstream repository where I created my own branch. I can commit to this branch and then create a pull request to the upstream. Committing again to the fork will naturally update the PR as well. This all works.

The issue is I want to add the ability to undo/delete a commit in the fork's branch using the github api, currently I am using the PyGithub package in python to interface with the Github Api but am willing to just send a request to the api directly if it isn't supported in PyGithub.

Code/Attempts

git = Github(base_url="...", login_or_token="...") # create github connection
repo = git.get_user().get_repo("...") # will get fork

ref = repo.get_git_ref("heads/"+branch_name) # get ref to branch

## Attempt 1
# ref.delete() # will delete entire branch

## Attempt 2
# last_commit = repo.get_branch(branch_name).commit.sha # get commit at head of branch
# ref = repo.get_git_ref(last_commit) # does not accept sha even though documentation says it should https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#get-a-reference
# ref.delete() # maybe it will delete just the commit?

## Attempt 3
# last_commit = repo.get_branch(branch_name).commit.sha # get commit at head of branch
# ... unsure how to edit ref to remove commit before making an update/edit happen
# ref.edit(sha=last_commit)

Normally if I was doing things locally I would just use git reset or git rebase to solve the problem but after skimming the documentation couldn't find a similar api command for the remote repo. Any ideas?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.