Export a stash to another computer

Alternatively, you can copy the entire local stashes(+ other local branches, local tags, etc) to another computer as follows:

  • git pull on both your old and new git directory to ensure that both have the latest changes (Or make sure that both repos have the same HEAD using git reset --hard commit-hash).
  • copy the .git folder from the old git directory to the new repository

alternatively you can create a branch from your stash (on computer 1), using

git stash branch stashed_changes_branch

commit your changes:

git commit -a

then add it as a remote on computer 2:

git remote add pc1 user@computer1:/path/to/repo

now you can retrieve the remote information using

git fetch pc1

now you can import the commit in the way you want; using git cherry-pick, git rebase or whatever you like... If you want it to look like you just did git stash apply; you can use git cherry-pick --no-commit.


If you have no direct connection between computer1 and computer2; you can use a remote (like github or something similar):

git push origin stashed_changes_branch

and on computer2:

git fetch

You can apply a patch file (without committing the changes yet) by simply running

git apply patchfile

Then you can simply create a new stash from the current working directory:

git stash

You can create stash as patch file from one machine,then can share that patch file to another machines.

Creating the stash as a patch

$ git stash show "stash@{0}" -p > changes.patch

The “stash@{0}” is the ref of the stash.It will create patch file with latest stash. If you want different one use command $ git stash list to see your list of stashes and select which one you want to patch.

Applying the patch

Now transfer that stash to another machine and paste it into the root folder of your project. Then run this command

$ git apply changes.patch

If there is mistake and you want to reverse the change

$ git apply changes.patch --reverse

Tags:

Git