Improve error handling and remove usage of git reset