How do I reset a Heroku git repository to its initial state?

I have got a web application within a git repository. Due to historic reasons the web application is not at the root of the repository, it is within a folder called website. Beside that there are some other folders, so that I have got the following structure:

+- .git
+- otherFolder1
+- otherFolder2
+- otherFolder...
+- otherFolderN
+- website

The website is run on Heroku. As Heroku demands that your web application is at the root of a git repository, until now I used a build process which copied the website folder to a completely different (external) folder with its own git repository. Then I was able to push from there to Heroku and everything was fine.

  • GitHub Organization Pages without named repository
  • git creates files ending in ~?
  • How do I replace a git submodule with another repo?
  • Python subprocess “git gc” stderr is not captured
  • Sourcetree on OSX looking for “credential-oskeychain” rather than “credential-osxkeychain”
  • Other consequences of `git push --force`?
  • Now, since git includes the subtree command this is not necessary any longer, as I could directly push from my initial folder, but just the website sub-folder, using:

    git subtree push --prefix=website heroku master

    Basically, this works perfectly. I only have one problem: As the previous commits to Heroku came from a completely different git repository, the history of both doesn’t match each other – so Heroku detects a non-fast-forward push, and rejects the subtree push.

    So how do I deal with this?

    • Idea 1: Force push. Tried that, but doesn’t work as git subtree push does not have a --force option (or anything similar).
    • Idea 2: Clear Heroku’s repository and start from scratch again.

    I’d love to go with idea 2, but I have no idea of how to achieve this.

    My first approach was to run a git push heroku :master, but Heroku detects this and denies it.

    Of course, I could destroy the app and recreate it, but then all domain assignments and add-ons are gone as well, and I’d like to avoid that.

    Any other ideas?

  • What does the -f option mean for the git rm command?
  • git show HEAD - How to skip on large files such as Illustrator files while reviewing files
  • In Git, how can I reorder (changes from) pushed commits?
  • how to restore deleted file
  • Package management in git for windows?
  • How to share a git feature (or topic) branch with multiple developers
  • 2 Solutions collect form web for “How do I reset a Heroku git repository to its initial state?”

    You can nest git commands to execute force push.

    For your case the command will be:

    git push heroku `git subtree split --prefix website master`:master --force

    For those coming here from Yeoman’s (lacking) deployment guide, there’s a much, much better and easier solution developed by X1011 and I urge you all to make your lives easier and use it!

    In contrast to the already issue-prone subtree method, this script actually retains your development commit delta history on your dist/build/release branch – and, you don’t even need to track the dist folder in your development branches.

    The setup process might look intimidating, but trust me, it’s not. It took me less than 10 minutes to set up and it just worked as promised on the first run, even on a Windows machine.

    If you’d like to automate it with Grunt, it is pretty easy. That’s how I did it:

    1. First download X1011’s to your main project folder.
    2. Follow the short configuration and setup guide.
    3. Install grunt-shell with node through this command: npm install grunt-shell --save-dev (--save-dev will add grunt-shell to your project’s dev dependencies, in case you didn’t already know). You may also use grunt-exec, they basically do the same thing, AFAIK.
    4. In Gruntfile.js, add the following object to initConfig:

    Add to initConfig object

        shell: {
            deployverbose: {
              command: 'sh -v',
              options: {
                  stdout: true,
                  stderr: true
            deploy: {
              command: 'sh',
              options: {
                  stdout: true,
                  stderr: true

    5 . Register a new task, or add it to your existing build task (make sure you you declare the target parameter):

    Add to existing build task as grunt build:deploy

    if (target && target.indexOf('deploy') > -1) {

    Standalone task grunt deploy, also allows the --verbose flag:

    grunt.registerTask('deploy', 'standalone deploy command', function () {
      if (grunt.option.flags().indexOf('--verbose') > -1) {'shell:deployverbose');
      } else {'shell:deploy');
    Git Baby is a git and github fan, let's start git clone.