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.If you pull new code from server it will overwrite your local code.
If your changes are important you must commit them and then pull from server. And them you will be able to compare the changes and merge those properly.
do : git commit -m "Any message"
then git pull
And then ONLY IF NEEDED git will ask you for solving merge conflicts.
I strongly advice you to use any GUI Based git manager. It will simplify a lot your work.
If your changes are so minor that it does not deserve a commit, you can put your local changes in a temporary place and then bring it back. do the fallowing.:
stash your changes git stash
. I will put all your local changes in a Temp place.
pull from server git pull
. All your changes will be overwrite.
bring back your local changes from stash git stash pop
. It will bring the local changes back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With