I have forked a repository, then I made some changes and it looks like I've messed up everything.
I wish to start it again from scratch, using the current upstream/master as the base for my work. Should I rebase my repository or delete it at all?
The simplest solution would be (using 'upstream' as the remote name referencing the original repo forked):
upstream
git remote add upstream /url/to/original/repo git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force
(Similar to this GitHub page, section "What should I do if I’m in a bad situation?")
Be aware that you can lose changes done on the master branch (both locally, because of the reset --hard, and on the remote side, because of the push --force).
master
reset --hard
push --force
An alternative would be, if you want to preserve your commits on master, to replay those commits on top of the current upstream/master. Replace the reset part by a git rebase upstream/master. You will then still need to force push. See also "What should I do if I’m in a bad situation?"
upstream/master
git rebase upstream/master
A more complete solution, backing up your current work (just in case) is detailed in "Cleanup git master branch and move some commit to new branch".
See also "Pull new updates from original GitHub repository into forked GitHub repository" for illustrating what "upstream" is.
Note: recent GitHub repos do protect the master branch against push --force. So you will have to un-protect master first (see picture below), and then re-protect it after force-pushing).
Note: on GitHub specifically, there is now (February 2019) a shortcut to delete forked repos for pull requests that have been merged upstream.
1.4m articles
1.4m replys
5 comments
57.0k users