Tool to change Google Apps primary domain and rename all users
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Change Primary Domain in a Google Apps Account

This is a tool to change Google Apps primary domain and rename all users, using the Google API Go client package.



  1. Set up your access to the Google API as described in the resources above
  2. Download the client_secret.json file from the developer console, place in the same directory as this project
  3. Build and run (or just run) the tool, passing the new and old domains as parameters
  4. Go to the URL displayed, which will perform the proper auth, paste token into console when prompted
  5. Confirm and off you go...


go run changeprimarydomain.go -new-domain -old-domain
go build changeprimarydomain.go
./changeprimarydomain -new-domain -old-domain


  • Works on OS X and Linux, unknown if this will work properly on Windows
  • Based on the Google Directory API Go Quickstart
  • To delete the cached auth credentials, remove the ~/.credentials/changeprimarydomain-<new domain>.json file
    • Example: rm ~/.credentials/
  • The 'Before you change your primary domain' document does not mention anything about renaming groups, but this console app does rename and alias all groups attached to the account
  • This console app can be run multiple times for the same new and old domains with no negative ramifications