Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull: keeps telling me to stash local changes before pulling

When I am trying to pull my git repository with "git pull", it keeps telling me that I have local changes although I have not touched any of the mentioned files. Can someone explain this behavior and knows a solution?

git status:

    # On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
#   (use "git pull" to update your local branch)
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   src/component/Provider.java
#   modified:   src/data/Cascading.java
#
no changes added to commit (use "git add" and/or "git commit -a")

Solved the problem. It was actually my fault not noticing that the remote repository has been reset to a previous version. Nevertheless if you experience this, the solution explained by Max Woolf will work!

like image 488
Jasper Avatar asked Dec 13 '13 14:12

Jasper


People also ask

How do you stash local changes before pulling?

If you want to keep those you can use the “stash” command before running the reset, and after doing the “pull”, you can “apply” or “pop” the stashed changes on top of your changes.

Does git pull get rid of local changes?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

How do you bypass your local changes to the following files would be overwritten by merge?

The “Your local changes to the following files would be overwritten by merge” error occurs when you try to pull a remote repository to your local machine whose contents conflict with the contents of your local version of the repository. To fix this error, either stash your changes away for later or commit your changes.


2 Answers

It sounds like your local branch does not have all of the changes on origin.

Firstly, stash your changes

git stash

Then, pull in the changes from origin.

git fetch origin && git rebase origin/(branch name)

Next, add the stash back in to your working directory:

git stash pop
like image 105
Max Woolf Avatar answered Sep 24 '22 07:09

Max Woolf


add all the files (adds all the files you changed)

git add .

then stash your changes

git stash

then you should be able to

git checkout branch && git pull

you have probably touched those files and you can go to the files and check with lines that have been touched. I usually use vscode for this. You can also just restore those files by git restore.

like image 21
deirdreamuel Avatar answered Sep 21 '22 07:09

deirdreamuel