I make some changes and commits to my project locally but didn't push them, then I change files in GitHub by adding new file and commit.
when I try to push my local commits android studio suggested to merge but when I try to merge it give me that error and whatever I do keep refusing to merge and show me that message.
and when I click merge shows me.
Error message:
My log:
What should I do?
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.
The Git “Your local changes to the following files would be overwritten by checkout” error occurs when you make changes on two branches without committing or stashing those changes and try to navigate between the branches. You can fix this issue by either stashing your changes for later or adding them to a commit.
With default strategy and default text merge driver, if there is no conflict, git never overwrites anything at merge. If there is a conflict then what "git does" fully depends on how person performing merge resolves the conflicts.
Your local changes will need to be stashed away while you perform the merge. To do that, git provides git stash
to save your uncommitted changes to a temporary location, and git stash pop
to apply them back to your local code.
This should work:
git stash
git pull origin master
git stash pop
Here's a good website to learn more about git: http://gitready.com/beginner/2009/03/13/smartly-save-stashes.html
But after looking at your screenshot, a merge doesn't seem like the best option for you. Instead a rebase would make more sense.
git stash
git pull --rebase origin master
git stash pop
Here are some resources to understand the difference between a merge and a rebase:
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