Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: move stash to repository in another directory

Tags:

git

git-stash

I have a local stash on a directory.

For some reasons, I had to re-import the same remote project into another directory.

Is there a way to move my stash from my old directory to the new created one since they follow the same remote project and branches ?

like image 773
Magnas Avatar asked Jan 04 '16 10:01

Magnas


People also ask

Can I push git stash to remote?

Git stash saves the uncommitted changes locally, allowing you to make changes, switch branches, and perform other Git operations. You can then reapply the stashed changes when you need them. A stash is locally scoped and is not pushed to the remote by git push .

How do I push a git repository to another repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.


2 Answers

You should be able to copy the .git directory from the old repo over the new one. Git stores every object in files within that directory so that should return your stash.

like image 54
BookOfGreg Avatar answered Nov 05 '22 01:11

BookOfGreg


You can use git stash branch to create a branch from your stash:

$ git stash branch <branchname> [<stash>]

This command performs the following:

  • Creates a new branch with <branchname>
  • Switches you to the new branch
  • Applies the specified stash (or the latest stash if omitted)
  • Stages all stashed changes for commit

After you commit and push the changes on this branch, you can then fetch or pull from it.

like image 29
haggai_e Avatar answered Nov 05 '22 01:11

haggai_e