Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git wont pull because of changed files

Tags:

git

So say I change file and then do a pull. Git will complain because the local repo hasn't been saved and will be overwritten. If I then remove that addition and make the file the same as it was before (same as the remote repo), will the pull occur then?

like image 535
Funsaized Avatar asked Jan 29 '26 14:01

Funsaized


2 Answers

Yes. This is common situation, that you have some changes in the working directory and then you need to pull. Usually you have to choose from:

  • Permanently remove your changes and then pull:

    $ git reset --hard
    $ git pull
    
  • Put your changes away, do the pull and then put your changes back:

    $ git stash
    $ git pull
    $ git stash pop   # May result in a merge conflict
    
  • Commit your changes before you pull:

    $ git add -A .                     # stage all changes
    $ git commit -m "my commit message"
    $ git pull                         # May result in a merge conflict
    

The last choice (using commit) I can only recommend, if your branch is configured to use 'rebase' instead of the default 'merge'.

From https://git-scm.com/docs/git-config

branch.<name>.rebase When true, rebase the branch <name> on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run. See "pull.rebase" for doing this in a non branch-specific manner.

When preserve, also pass --preserve-merges along to git rebase so that locally committed merge commits will not be flattened by running git pull.

When the value is interactive, the rebase is run in interactive mode.

NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase[1] for details).

like image 126
Boris Brodski Avatar answered Jan 31 '26 09:01

Boris Brodski


Yes. Your working directory must be clean(-ish) when pulling, that is, you have to either remove or commit your changes.

From git help pull:

If any of the remote changes overlap with local uncommitted changes, the merge will be automatically cancelled and the work tree untouched. It is generally best to get any local changes in working order before pulling or stash them away with git-stash(1).

like image 33
AnoE Avatar answered Jan 31 '26 08:01

AnoE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!