Mike
Mike

Reputation: 963

Unable to reset my fork to upstream

I am new to Git, so I am making many mistakes as I go along. One of these mistakes was committing all my changes to my master branch, which means that my pull requests have grown unreasonably large. What I'd like is for my master branch to be a "clean" version of the upstream repository which I forked from. From there, I will make manageable pull requests from branches off of master.

To do this, I tried the following:

  1. Save my work so far in a separate branch

  2. Reset master to the repo upstream using:

git reset --hard upstream/master

I then cleaned my local branch with:

git clean -f -d

This seems to have no effect on my remote master branch on GitHub, which remains at the last commit that I made.

I've been using the Mac GitHub app which shows that my branch is reset until I press "sync branch", at which point the branch reverts back to my last commit.

Please let me know if I can clarify anything. Thanks.

Upvotes: 0

Views: 472

Answers (1)

Sam
Sam

Reputation: 20486

Changing your local branches will never affect your remote branches. You would need to run:

git push upstream master

This will most likely fail, though, since you have modified history (a non fast-forward commit). If it does, you will need to force this push (warning, this will rewrite history and can cause issues with collaboration; make sure everyone knows to reset their master to the upstream):

git push upstream master -f

The reason "sync branch" on the GitHub app fails is because it assumes (rightfully so) that you want to keep your remote's history in tact. Meaning it will first git pull upstream master before git push upstream master. This will fast forward your local branch back to where it was and then push (no changes).

Upvotes: 1

Related Questions