Broncos423 Broncos423 - 1 year ago 87
Git Question

Git wont pull because of changed files

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?

Answer Source

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'.


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).