it happened more than once to leave the office having only saved a stash of uncommitted code.
So, if I wanted to keep working on the same feature, I had to SSH to my host, create a disposable branch, commit the stash and push the new branch to the development repository.
Now I wonder if there is a cleaner, more practical solution for "copying/exporting" a git stash to another local repository. I have already ruled out SCP'ing the local repository on my office machine, because I could have some work in progress on my laptop, too.
P.S.: my question looks like the continuation of this one
You can use git stash show
to make a patch and then git apply
it on your home machine.
The stash is saved as a special type of commit, and so it is available in the git object database. But, the reference to that commit is outside of the namespace that is typically made available for fetching.
You could make the most recent stash available for fetching by running the following on the source repository:
git symbolic-ref refs/heads/exported-stash refs/stash
This will create a branch named exported-stash
which can be fetched like any other branch. You can use a different name if you like, but avoid using stash
since that will result in some annoying warnings about the name being ambiguous with the actual stash. After fetching from the remote it can be applied on another repository with:
git stash apply origin/exported-stash
(assuming that it was fetched from the remote origin
).
After making changes you could even stash those locally and push the updated stash back to the origin with:
git push origin +stash:exported-stash
The +
turns this into a forced push, but in this case that is actually safe. The old version of the stash on the origin will just be moved to stash@{1}
since the list of stashes is saved as a log of references.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With