git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Git Stash Synchronization - Best Workflow?

From
Brooke Kuhlmann <brooke@alchemists.io>
Date
Aug 31, 2025, 23:25 UTC
Message-ID
<7B1CCA36-23F1-410D-84ED-6E965989EA8B@alchemists.io>
Hello.
When using Git 2.51.0, what is the correct way to safely export your stash and then keep that stash up-to-date? Here's an example workflow:
touch demo.txt

git stash push --include-untracked --message "Demo" git stash export --to-ref "refs/stashes/$USER" git push origin "refs/stashes/$USER"

git stash pop stash@{0} git push origin "refs/stashes/$USER"

git stash push --include-untracked --message "Demo II" git stash export --to-ref "refs/stashes/$USER" git push origin "refs/stashes/$USER"

Notice, in the middle, I pop the stash only to rename it. Upon pushing these changes back up, I get the following error:
To https://github.com/bkuhlmann/test
 ! [rejected]                  refs/stashes/bkuhlmann -> refs/stashes/bkuhlmann (non-fast-forward)
error: failed to push some refs to 'https://github.com/bkuhlmann/test'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you want to integrate the remote changes, use 'git pull'
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The work around is to use `git push --force` when pushing updates. I'd like to use `git push --force-with-lease` but that doesn't work.
I realize that force pushing over your remote stash makes a lot more sense since you typically never share a stash with folks but was thinking it would be nice to ensure you don't accidentally override your remote stash when working on different machine when you forgot to import first. Basically, wanting to protect myself from myself. :)
Is force push the only way to handle this use case or is there a better approach? Thanks!
Next: Phillip Wood
Message 1 of 9 in “Git Stash Synchronization - Best Workflow?”
  1. Brooke KuhlmannAug 31, 2025
  2. Phillip WoodSep 1, 2025
  3. Brooke KuhlmannSep 1, 2025
  4. Phillip WoodSep 5, 2025
  5. Brooke KuhlmannSep 6, 2025
  6. Phillip WoodSep 10, 2025
  7. Brooke KuhlmannSep 11, 2025
  8. Phillip WoodSep 19, 2025
  9. Brooke KuhlmannSep 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.