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?
This question is related to
git
Following @VonC great answer. Your GitHub company policy might not allow 'force push' on master.
remote: error: GH003: Sorry, force-pushing to master is not allowed.
If you get an error message like this one please try the following steps.
To effectively reset your fork you need to follow these steps :
git checkout master
git reset --hard upstream/master
git checkout -b tmp_master
git push origin
Open your fork on GitHub, in "Settings -> Branches -> Default branch" choose 'new_master' as the new default branch. Now you can force push on the 'master' branch :
git checkout master
git push --force origin
Then you must set back 'master' as the default branch in the GitHub settings. To delete 'tmp_master' :
git push origin --delete tmp_master
git branch -D tmp_master
Other answers warning about lossing your change still apply, be carreful.
Love VonC's answer. Here's an easy version of it for beginners.
There is a git remote called origin
which I am sure you are all aware of. Basically, you can add as many remotes to a git repo as you want. So, what we can do is introduce a new remote which is the original repo not the fork. I like to call it original
Let's add original repo's to our fork as a remote.
git remote add original https://git-repo/original/original.git
Now let's fetch the original repo to make sure we have the latest coded
git fetch original
As, VonC suggested, make sure we are on the master.
git checkout master
Now to bring our fork up to speed with the latest code on original repo, all we have to do is hard reset our master branch in accordance with the original remote.
git reset --hard original/master
And you are done :)
(Not everyone likes doing things through the git command line interface)
Once this has been set up, you only need to do steps 7-13 from then on.
Fetch > checkout master branch > reset to their master > Push changes to server
Double click on your "master" branch to check it out if it is not checked out already.
Find the commit that you want to reset to, if you called the repo "master" you will most likely want to find the commit with the "master/master" tag on it.
Right click on the commit > "Reset current branch to this commit".
In the dialog, set the "Using mode:" field to "Hard - discard all working copy changes" then press "OK" (make sure to put any changes that you don't want to lose onto a separate branch first).
Your Done!
Source: Stackoverflow.com