Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most practical way to keep working on a git stash on a different computer?

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

like image 377
ziu Avatar asked Jul 23 '13 13:07

ziu


2 Answers

You can use git stash show to make a patch and then git apply it on your home machine.

like image 126
Carl Norum Avatar answered Sep 19 '22 17:09

Carl Norum


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.

like image 39
qqx Avatar answered Sep 19 '22 17:09

qqx