Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Diff, Status, and Sync

Scenarios for collaborating with others:

  1. I want to compare locally edited secrets with upstream changes
  2. I want to sync locally modified changes with upstream

I want to compare locally edited secrets with upstream changes

If you have modified a secret locally and someone else has pushed changes to the same secret, you can compare them using ctg diff.

First, let’s assume you have edited a secret locally:

cd /tmp/myproject-clone
echo "DB_PASSWORD=my-local-password" > secret1.env

Now, you pull the latest changes from the upstream repository:

git pull origin main

Note

Since secret1.env is ignored by git, there will be no git conflict. However, secret1.env.cott.age (the encrypted file) and secret1.env.cott.toml will be updated.

Now you can compare your local changes with the upstream version:

ctg diff
diff --git a/secret1.env b/secret1.env
--- a/secret1.env
+++ b/secret1.env
@@ -1 +1 @@
-DB_PASSWORD=editedsecret
+DB_PASSWORD=my-local-password

I want to sync locally modified changes with upstream

If you want to update the encrypted files with your local changes, you can use ctg sync.

First, check the status of your secrets:

ctg status
encrypt secret1.env
   into secret1.env.cott.age

Now run ctg sync to encrypt the modified files:

ctg sync
encrypt secret1.env
   into secret1.env.cott.age
   edit secret1.env.cott.toml

Verify that everything is in sync:

ctg status
# No output means everything is in sync

Now you can commit and push the changes to the upstream repository:

git add .
git commit -m "Sync local changes to upstream"
git push origin main
[main XXXXXXX] Sync local changes to upstream
 2 files changed, 3 insertions(+), 3 deletions(-)
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 20 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), X.XX KiB | X.XX MiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
To /tmp/upstream.git
   XXXXXXX..XXXXXXX  main -> main