Skip to content

Instantly share code, notes, and snippets.

@shirhatti
Created March 27, 2025 16:44
Show Gist options
  • Save shirhatti/5bd74831db19e0cd0b9b610f6ca91133 to your computer and use it in GitHub Desktop.
Save shirhatti/5bd74831db19e0cd0b9b610f6ca91133 to your computer and use it in GitHub Desktop.

Approach

  1. Stash-like tracking: Instead of using git stash, use a sequence of temporary commits on a detached HEAD.
  2. Detached HEAD commits: Each incremental automation change is committed but does not affect the working branch.
  3. Reflog for tracking: Each commit is reachable via git reflog, so you can review each change step by step.
  4. No changes left behind: Once the tool completes execution, the working directory still contains uncommitted changes.

Step 1: Start in a Detached HEAD

Before making changes:

git checkout --detach

Step 2: Save Incremental Changes

Each time an automation step modifies files, create a commit:

git add .
git commit -m "Automation Step N"

This creates a history of changes without affecting the main branch.

Step 3: Track Commit History

Each commit has a git reference, which you can extract using:

git reflog

This allows a reviewer to check the changes step by step.

Step 4: Restore the Working Branch

git checkout -  # Switch back to the previous branch
git reset HEAD  # Keep working directory changes, remove commit history

This ensures that: The branch stays untouched. The working directory still contains uncommitted changes.

Step 5: Print the Git References

At the end of the process, print commit refs for your review:

git reflog --oneline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment