Reputation: 3574
I have a private repository that is messed up. Not sure how, very difficult to tell.
I now want to do a
git checkout master
git fetch upstream/master
git make-my-master-the-same-as-upstream-master
No merge, no rebase. I do not want any changes from my master
in there. No new files. I want to be confident that my master is exactly the same as upstream/master
. No extra files. No merges. The same.
(For the local repository I use rm -rf
. But this then needs to be synced to github.)
(There are 100 similar questions with 500 recipes as answers each with subtle differences, but I do not think this has been asked/answered properly. Very crude, clean and start.)
Upvotes: 1
Views: 264
Reputation: 98
I suppose a few things.
git checkout master
git checkout master
git reset --hard $(git log origin/master --pretty=oneline | awk 'NR==1{print $1}')
git fetch upstream/master git make-my-master-the-same-as-upstream-master
git pull
Upvotes: 1
Reputation: 62906
First get all remotes up to date:
git remote update
Then go to the branch you want to reset, here:
git checkout master
Optional: take note of current state, possibly like this, quick&dirty:
git commit -a -m"messed up" # commit all changes
git tag messed_up_backup # store revision as tag
Then set the branch to what you want it to be via hard reset, in this case probably:
git reset --hard upstream/master
Upvotes: 1
Reputation: 42551
If you'll make your local master (of the messed up branch) to be "exactly the same as upstream/master" - you'll loose all your local changes. If this is what you want to do, there are many ways, one of them is:
Find the commit id that is in your master before the mess (even the initial commit will be fine). Lets say, it has sha1: 123abc
(just for example)
Make sure that you're on your local master
git checkout master
git reset --hard 123abc
gut pull
Note, that if you want to "back up" your changes anyway, maybe to cherry-pick a couple of them afterwards (who knows, maybe they still can be worthy), before doing the step 3, you can merely create a branch out of master with the pointer on the last commit (it will be identical to the messed up master but at least you won't loose the reference after calling git reset
during step 3)
Upvotes: 1