As I am trying to pull some changes from origin/master, I am getting this error :
error: Your local changes to the following files would be overwritten by merge
because I made local changes. I don't want to commit these changes, so I suppose I should use git stash
on my branch, then git pull origin master
My question is :
Thank you !
PS : yes, I googled, I just want to make sure I understood correctly.
Here is how your repo evolves when all is applied :
Before you pull, with your local modifications :
--*--*--*--*--*--*--A--B (<- some changes you did not commit yet)
\ ^
\ master: your latest local commit on master
\
*--*--C origin/master: the latest commit on the remote repo
after git stash
:
B <- stash: git stored local changes in its stash
/
--*--*--*--*--*--*--A <- master: the files on your disk have been restored
\ to their state in "master"
\
\
*--*--C origin/master: the latest commit on the remote repo
after git pull
:
B <- stash
/
--*--*--*--*--*--*--A--D <- master: merged remote branch in local branch
\ /
\ /
\ /
*--*--C---/
^ origin/master
git
applies the action it usually does when pulling: merge the remote changes in your local branch.
after git stash apply
:
B <- stash
/
--*--*--*--*--*--*--A--D--B' <- modifications stored in B (not committed yet)
\ /
\ /
\ /
*--*--C----
^ origin/master
git
re-applies the modifications stored in the stash on top of the new leading commit
The caveats are :
git pull
) may trigger some conflicts, which you will need to solve before actually reaching the state D
in the diagramgit stash apply
) may also trigger some conflicts, if your local changes (the ones stashed in B
) actually interfere with some modification from origin/master
.B'
in the diagram.