Skip to content

Commit

Permalink
fix(setup): Remove step to hard reset this repo
Browse files Browse the repository at this point in the history
This is a slightly embarassing story, but needs to be told for context.

When I was creating my `dotfiles` repo, I copied the
`initialize_git_repository.sh` from this repo. It worked as following:

- Initialize git at the root of this project, if this is not a git repo
- Add an origin URL as remote
- Fetch the changes from origin/master
- Run `git reset --hard origin/master` to mirror origin/master

I created all the other files and tested it locally. More than 70% of
my final work was done. And, then I ran the `setup.sh` script which
called `initialize_git_repository.sh`. Since, I had not even initialized
git in the repo (and thereby had not committed any changes), it ran all
the above steps. As a result, I lost all my changes from the past more
than 6 hours in under 5 seconds. It was devastating, to say the least.

So, I'm removing the final step to hard reset because this could easily
be weaponified to delete all the files on a computer. The user must
run `git reset --hard` herself to be in full control.

However one positive things came out out this and I learnt an important
lesson.

> Always backup your data, even when you don't!
  • Loading branch information
musq committed Jul 27, 2019
1 parent 19d60d8 commit eabf638
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/os/initialize_git_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ update_git_repository() {
declare -r remote="$1"
declare -r branch="$2"

execute \
"git fetch $remote $branch \
&& git reset --hard $remote/$branch" \
execute "git fetch $remote $branch" \
"Update the Git repository"

}
Expand Down

0 comments on commit eabf638

Please sign in to comment.