Script recovery and repository migration

If you accidentally delete a script or folder in the Earth Engine Code Editor, or need to migrate a repository to a new account, the full commit history is preserved in the Git logs on our servers. While the repository icon in the Code Editor reverts an entire repository to a previous state, cloning the repository locally with standard Git command-line tools lets you selectively restore individual scripts or folders without losing newer changes to other scripts.

First complete the Prerequisites, and then choose one of the following options depending on your task:

Prerequisites

Step 1: Generate Git credentials

Because Google-hosted Git repositories use secure token authentication, you must first generate your local Git credentials:

  1. Open an incognito or private browsing window in your web browser and visit the Git password generator: earthengine.googlesource.com/new-password (Note: Sign in exclusively with your Earth Engine registered Google Account. If you are migrating a repository to a new account under Option C, first share the old repository with your new account and sign in here with your new Google Account.)
  2. Copy the entire block of generated shell commands shown on the screen.
  3. Open a terminal (command line) on your computer, paste the copied commands, and run them. This configures your machine's Git cookie credentials automatically.
  4. If this is your first time using Git on your computer, configure your author name and email so Git lets you create commits:

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    

Step 2: Clone your repository (Options A and B)

If you are migrating a repository between accounts, skip to Option C. To restore a deleted script or folder, clone your repository in your local terminal by replacing username and repository with your Earth Engine details (you can also copy the exact clone command by clicking the icon next to the repository name in the Scripts tab):

git clone https://earthengine.googlesource.com/users/username/repository

Once complete, navigate into the cloned folder:

cd repository

Option A: Restore a deleted script

To recover a deleted script file (for example, MyScript or MyFolder/MyScript):

  1. View the file's history to find the deletion commit and the commit immediately prior to it (listed right after it in the log output):

    git log --oneline -- "MyScript"
    
  2. Restore the last version where the file still existed to your folder (replace <commit_hash> with the hash of the commit prior to deletion, or use <deletion_commit_hash>~1):

    git checkout <commit_hash> -- "MyScript"
    
  3. Commit and push the restored script back to the server:

    git commit -m "Restore MyScript from history"
    git push origin
    

Once pushed, reload the Code Editor Scripts tab in your browser (or click the button at the top of the Scripts tab) to see the restored script.

Option B: Restore a deleted folder

To recover a deleted folder and all the scripts within it (for example, MyFolder/):

  1. Check your Git commit logs to find the deletion commit and the commit immediately prior to it (listed right after it in the log output):

    git log --oneline -- "MyFolder/"
    
  2. Restore the last version where the folder still existed to your folder (replace <commit_hash> with the hash of the commit prior to deletion, or use <deletion_commit_hash>~1):

    git checkout <commit_hash> -- "MyFolder/"
    
  3. Commit and push your recovered folder back to the server:

    git commit -m "Restore MyFolder and all its scripts"
    git push origin
    

Once pushed, reload the Code Editor Scripts tab in your browser (or click the button at the top of the Scripts tab) to see the restored folder.

Option C: Migrate a whole repository

If you need to migrate an entire repository and its complete commit history to a new account (for example, when transitioning between institutional and personal accounts):

Credentials and permissions: If you are migrating a repository between two different Google Accounts (for example, from a university or work account to a personal account), you must ensure your new account has permission to read the old repository before you start:

  • The Sharing Prerequisite: Sign in to your old Code Editor account, click the icon next to your old repository name, and share it with your new Google Account email address, granting it Reader access.
  • By doing this, you only need to authenticate on your local computer once (using your new account's Git credentials generated in Step 1). Your new account will have permission to both clone from your old repository and push to your new one, avoiding credential conflicts.
  1. Clone your old repository locally using standard Git:

    git clone https://earthengine.googlesource.com/users/old_username/old_repository
    
  2. Create a new, empty repository from the New > Repository menu in your new Code Editor account. (Note: Don't create or save any scripts or folders in the new repository before pushing, or the push will fail.)

  3. Navigate into your local cloned directory:

    cd old_repository
    
  4. Push your entire local commit history and scripts directly to your new, empty Earth Engine repository:

    git push https://earthengine.googlesource.com/users/new_username/new_repository --all
    

Once pushed, reload the Scripts tab in your new account's Code Editor (or click the button) to see the migrated repository and history.