1

I want to sync the local branch with the remote git branch. I tried to do git pull but it fails with the below error

error: The following untracked working tree files would be overwritten by merge:

Please remove or move them before you can merge.

Is there a command which just overwrites the local changed files and just updates with the changes in the repo. Even if there are conflicts I just want the changes in the remote repository to be applied.

Is there one command I can run to get this done?

Stefan
  • 109,145
  • 14
  • 143
  • 218
Bourne
  • 1,905
  • 13
  • 35
  • 53
  • 1
    See [here](http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull). – flyx Jun 13 '13 at 06:33

2 Answers2

1

You have to commit first:

git commit -a -m "commit message"

after that you can pull from remote

herrhansen
  • 2,413
  • 1
  • 14
  • 15
  • What does git commit -a do? – Bourne Jun 13 '13 at 06:45
  • the -a stands automatic staging of the modified and deleted files, if you have untracked (new) files in your repo, you have to add them by `git add .` first – herrhansen Jun 13 '13 at 06:50
  • What command can I use to remove all the commits made? – Bourne Jun 13 '13 at 06:59
  • Why do you want that? You can remove the .git folder and reinit for having a new clean repo or you can use `git reset`, the options can you find here: https://www.kernel.org/pub/software/scm/git/docs/git-reset.html – herrhansen Jun 13 '13 at 07:04
  • I don't want those changes any more. I'm not planning to push them because of the change in business requirements. – Bourne Jun 13 '13 at 07:08
  • You can reset to repostory state http://stackoverflow.com/questions/1628088/how-to-reset-my-local-repository-to-be-just-like-the-remote-repository-head – herrhansen Jun 13 '13 at 07:12
  • The error is with untracked files, the `-a` option adds only the tracked files to the commit. Also `git reset --hard` does not affect untracked files. – Schleis Jun 14 '13 at 13:13
0

You have copies of files that were added in the remote branch but are not being tracked in your local. Delete or move those files then you will be able to pull.

When you do git status there will be a section of listed as Untracked Files. You can do git stash -u and it will add all the untracked files to a stash. Then you will be able to pull the changes without a problem.

Schleis
  • 41,516
  • 7
  • 68
  • 87