Skip to content

Instantly share code, notes, and snippets.

@dakoctba
Last active May 29, 2025 21:39
Show Gist options
  • Save dakoctba/7676845 to your computer and use it in GitHub Desktop.
Save dakoctba/7676845 to your computer and use it in GitHub Desktop.
How To Reset Your Github Fork

##How To Reset Your Github Fork

Let’s say I want to contribute to a project on github. The project repository is at wp-cli/wp-cli. First I fork it, and then clone the resulting repository, scribu/wp-cli:

git clone --recursive [email protected]:scribu/wp-cli.git
cd wp-cli

Now, I make some commits to master, push them to my fork and open a pull request. Piece of cake:

git commit -m "awesome new feature"
git push

But, what happens if my pull request is rejected or only certain commits are accepted? I’m left with a dirty master branch. Oh noes!

There are two ways of solving this:

A. Delete my fork and create it again via the github interface. Can’t get any easier than that.

B. Use git reset:

git remote add upstream git://github.com/wp-cli/wp-cli.git
git fetch upstream
git branch backup
git reset --hard upstream/master
git push --force

If I made a mistake, I can rescue my commits by calling git checkout backup.

PS: You can avoid this problem entirely by pushing your commits to a branch, instead of to master.

From: (http://scribu.net/blog/resetting-your-github-fork.html)

@gormonn
Copy link

gormonn commented Sep 16, 2023

Thank you!

@FAReTek1
Copy link

FAReTek1 commented Dec 24, 2024

Thank you!

also maybe you should edit the top line to fix the formatting

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