Skip to content

Instantly share code, notes, and snippets.

@MathyV
Created March 22, 2018 19:30
Show Gist options
  • Save MathyV/80d2507f6843e391211f2ec5e0effa3c to your computer and use it in GitHub Desktop.
Save MathyV/80d2507f6843e391211f2ec5e0effa3c to your computer and use it in GitHub Desktop.
Force push with pygit2
# I had a need to force update and push the master branch
# Took me a while to find this so I thought I'd share
# Just add a + in front of the branch name and it will work
branch = "refs/heads/master"
repo.create_reference(branch, "refs/heads/develop", force=True)
repo.remotes['origin'].push(['+' + branch], callbacks=callbacks);
@homeday
Copy link

homeday commented Oct 25, 2022

great code, but can you please help to share whether there will be a new remote branch?

@MathyV
Copy link
Author

MathyV commented Dec 6, 2022

great code, but can you please help to share whether there will be a new remote branch?

Not sure what you are getting at @homeday but if you force push it will overwrite the existing remote branch or create a new one if it doesn´t exist yet.

@homeday
Copy link

homeday commented Dec 9, 2022

ok, got it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment