Articles

How to deploy a specific Git commit without changing your branch

Build an exact Git commit by SHA on Gregale, stage it before serving traffic, and know when to roll back an existing release instead.

Updated

To deploy a specific Git commit without changing your branch, use the full 40-character commit SHA as the deployment ref. On an existing Gregale app, open Deploy → Review first, enter the repository and SHA in Ref, then click Review. You can build an older commit even if it never had a deployment. You do not need to reset, force-push, or rebind the production branch.

A manual deployment and your branch's auto-deploy rules are separate. On a connected app, deploying a SHA does not change which branch triggers future deployments. The next eligible push can still trigger a new deployment.

Build an older commit or roll back an existing release?

What you wantWhat to use
Build a Git commit that was never deployedDeploy by full commit SHA. Gregale builds a new revision from that source.
Return to a previously built and retained revisionUse a rollback. It reuses the existing deployment instead of rebuilding its Git commit.
Decide which revision is serving nowCheck production traffic and the exact deployment. The latest build is not necessarily the serving release.

Rebuilding an old SHA uses today's build inputs outside Git unless you pinned them: lock dependencies and pin base images by digest when byte-for-byte repeatability matters. Neither deploying an old SHA nor switching traffic on its own undoes a database migration.

From the Gregale dashboard

  1. Start on an existing app with access to the repository through the Gregale GitHub App. Under Deploy, select Review first.
  2. Paste the full SHA into Ref and select Review. Compare the resolved Commit with the SHA you copied. The review reads the source and pins the app's current release state; it does not start a build or bind the repository.
  3. If the action says Stage at 0%, you can build and verify the candidate before it receives normal traffic. If it says Roll out reviewed commit, the app is a service or worker and this path does not offer a 0% stage. Do not use that action just to inspect the old code.
  4. Once the candidate is ready, verify the exact deployment before promoting it. If Gregale says the release changed since review, run a new review rather than blindly retrying.

Review first builds the selected code, not the full release configuration from that point in time. It does not import that commit's triggers, workflows, operations, or release command. Workflows and operations remain as configured on the serving release.

Use Review first when you want to avoid changing setup on an unbound app. Build and deploy on an unbound app may also connect push-to-deploy to the repository's default branch.

From a clean Git checkout

No GitHub App installation is needed for this CLI path: Gregale builds the committed source you upload from your machine. Download the fixture to practice on a disposable app. Its current commit returns {"version":"main"} at /version; the older commit returns {"version":"older"}.

After extracting the ZIP, run this inside the fixture directory with Git, curl, jq, OpenSSL, and the Gregale CLI. Export FAAS_TOKEN for a disposable workspace with permission to create and deploy apps. Use the same token for the guard and the CLI.

bash
set -euo pipefail
bash init.sh example-repo

APP="demo-exact-sha-$(openssl rand -hex 8)"
APP_ID="$(bash create-app.sh "$APP")"
test -n "$APP_ID"

cd example-repo
export GREGALE_TOKEN="$FAAS_TOKEN"
export GREGALE_API_URL=https://api.gregale.dev FAAS_API=https://api.gregale.dev
g() { gregale --non-interactive --json "$@"; }

MAIN="$(git rev-parse main)"
OLDER="$(git rev-parse main^)"
CURRENT="$(g deploy --name "$APP" --source=head --yes | jq -er '.id')"

git switch --detach "$OLDER"
test "$(git rev-parse HEAD)" = "$OLDER"
test "$(git rev-parse main)" = "$MAIN"

CANDIDATE="$(g deploy --name "$APP" --source=head --no-traffic --yes | jq -er '.id')"
test "$CANDIDATE" != "$CURRENT"
g release verify "$CANDIDATE" --app "$APP" --path /version |
  jq -e --arg id "$CANDIDATE" '
    .verified and .deployment_id == $id and .http_status == 200
    and (.body | fromjson) == {version: "older"}'
gregale release traffic status "$APP"

create-app.sh requires a successful creation receipt for a new internal app before any deploy. If the name already exists or the response cannot be verified, stop rather than deploying to the name.

--source=head uses the checked-out commit, not local edits. Detaching HEAD does not move main. On an existing repository, use a temporary detached Git worktree if you want to leave your current checkout alone.

For this fixture, check that the baseline is still at 100% and the candidate is at 0%. To switch the disposable app, run the guarded promotion below. It refuses if the baseline you checked is no longer serving at 100%.

bash
g release traffic promote --app "$APP" --release "$CANDIDATE" --if-serving "$CURRENT"
gregale release traffic status "$APP"

Confirm the candidate gets 100%. If the app has a reachable stable URL, request /version through that URL using its normal access controls. An exact-deployment check and a stable URL request answer different questions. Clean up the disposable app when you are done.

What was tested: The downloadable CLI fixture was run on a disposable Gregale app. The deployed commit IDs and returned version markers matched, and guarded promotion moved the older revision from 0% to 100%. The dashboard walkthrough describes the reviewed-source flow; the hosted fixture did not exercise a connected GitHub account.

Questions

Can I deploy a Git commit that was never deployed before?

Yes. Select the repository and paste its full 40-character SHA into Ref for an existing Gregale app. This builds a new deployment, unlike a rollback to a retained revision.

Does deploying by SHA change the production branch?

No. A reviewed deployment of an exact SHA does not move your Git branch or change an existing Gregale branch binding. Future eligible pushes still follow your normal deployment policy.

How can I verify a pinned commit before it serves traffic?

For an eligible request-mode app, stage the reviewed commit at 0% or deploy a detached checkout with --source=head --no-traffic. Verify the candidate by deployment ID and check the traffic table before promoting it.