Git Stash Synchronization - Best Workflow?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux