Update a Severely Out of Date GitHub Repository Fork

Recently, I received notification from Planet PowerShell that they will be removing blogs that do not support HTTPS as of August 1st. I had forked their repo on GitHub over a year ago, added my blog, and submitted a pull request. I hadn't touched my fork of their repo since then. It was severely out of date and in an unknown state.

Taking a look at it on my system showed my local copy only had one remote which was my fork on GitHub.

1git remote show
2git remote show origin

git-update-fork1a.jpg

I could see that one of the files had been updated in my local copy, but not committed. I didn't have a clue about what changes had been made or why they were made.

1git status

git-update-fork2a.jpg

The git diff command can be used to show what's been changed as shown in the following example.

1git diff src/Firehose.Web/Authors/MikeRobbins.cs

git-update-fork3a.jpg

I don't care about those changes. I'll simply check that file out again to discard those changes.

1git checkout src/Firehose.Web/Authors/MikeRobbins.cs

git-update-fork4a.jpg

Now I'll add the upstream remote and fetch any updates, or a copy of it in this scenario.

1git remote add upstream https://github.com/planetpowershell/planetpowershell.git
2git fetch upstream

git-update-fork5a.jpg

All that needs to be done now is to merge the changes from upstream into my current branch.

1git merge upstream/master

git-update-fork6a.jpg

I know why they call this a GitHub fork. Stick a fork in it, this repo is done!

That was wishful thinking. While the previous command would work in many cases, this repo is too far out of date. I could simply delete my local copy and my forked copy of it on GitHub and then fork it again along with cloning it locally again. That's a lot of trouble and work. I'll simple do a hard reset on my local copy and then force those changes into my forked copy on GitHub.

Warning: Use the following commands at your own risk!

Per the Git documentation, the following command "Resets the index and working tree. Any changes to tracked files in the working tree are discarded". You will loose any changes you've made using these commands.

Make sure you understand what is happening before proceeding.

1git reset --hard upstream/master
2git push --force

git-update-fork7a.jpg

My local copy and my forked copy on GitHub are now in sync with the Planet PowerShell repo on GitHub.

1git status
2git remote show origin
3git remote show upstream

git-update-fork8a.jpg

Now I can make the necessary changes to my profile file to direct readers on Planet PowerShell to my blog site via HTTPS instead of HTTP and everyone will be happy!

µ