Question

Using Git on DigitalOcean server: error: The following untracked working tree files would be overwritten by merge

I am using Django for my site on DigitalOcean. So, I had to delete the migration files for one of my apps (accounts) and run makemigrations again. I don’t really recall when or why, but it has caused this error when I pull from origin:

```
$ git pull origin master
From https://github.com/...
...
error: The following untracked working tree files would be overwritten by 
merge:
    accounts/migrations/0001_initial.py
Please move or remove them before you merge.
Aborting  
```

Locally, my accounts app has only one migration:

```
accounts > migrations
__init__.py
0001_initial.py
```

When I run git status on the server, I get a lot of untracked files, and I can see two migrations related to my accounts app (even though locally I only have one migration file in the accounts/migrations) as well as other untracked files (not related to accounts app):

``` 
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
    accounts/migrations/0001_initial.py
    accounts/migrations/0002_alter_user_id.py
    ...
```

Given that I don’t want to mess with the production database, I don’t wish you to change the migration files on the server to replicate the local migration files unless this does not cause any problem for my server. So, how should I resolve this error?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Indeed, this is quite tricky as this is your production server. It sounds like someone has made changes directly on the production server without going through git. If you are working with a team, I could suggest getting in touch with them too to verify why this has been done.

Alternatively, what you could do is check the content of the accounts/migrations/0001_initial.py migration file on the server and your local environment and verify which is the correct one and update it accordingly.

In general, as there is only 1 file reported to be causing the problem, to solve this particular problem in git, what you could do is revert the untracked changes made to the file with git checkout -- accounts/migrations/0001_initial.py and then pull the latest changes as normal.

However as this is a production environment, I would strongly suggest taking a backup of both your database and files so that in case that anything goes wrong after you merge those changes, you could at least revert back to a working version of the website.

Regards, Bobby