You know that some indexed files and folder structure is old in a branch so you want to get the new versions from another. For that, we use git stash command. For more information, click git stash link.


Check current status


inanzzz@inanzzz:~/project$ git branch
branch-one
* branch-two
develop
inanzzz@inanzzz:~/project$ git status
On branch branch-two
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: dir-one/hello_one.txt
modified: file_one.txt
deleted: file_seven.txt
modified: file_two.txt

Save the changes


Saving the state of all the changes so we don't lose anything.


inanzzz@inanzzz:~/project$ git stash save
Saved working directory and index state WIP on branch-two: a08b95e First commit in branch-two branch
HEAD is now at a08b95e First commit in branch-two branch
inanzzz@inanzzz:~/project$ git status
On branch branch-two
nothing to commit, working directory clean

Switch branch


Switch to where we want to transfer our saved state.


inanzzz@inanzzz:~/project$ git checkout branch-one 
Switched to branch 'branch-one'
inanzzz@inanzzz:~/project$ git status
On branch branch-one
nothing to commit, working directory clean

Transfer the changes


Once all the conflicts resolved, job is done.


inanzzz@inanzzz:~/project$ git stash apply
Auto-merging file_two.txt
CONFLICT (content): Merge conflict in file_two.txt
Removing file_seven.txt
Auto-merging file_one.txt
CONFLICT (content): Merge conflict in file_one.txt

Check current status


inanzzz@inanzzz:~/project$ git status
On branch branch-one
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: dir-one/hello_one.txt
deleted: file_seven.txt

Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)

both modified: file_one.txt
both modified: file_two.txt