By Mark Reeves
I have my git automatically syncing the files in the repo to my droplet, but I have a database in there and everytime there’s a new update in the repo it also updates the database. Any ideas how to fix it? I also tried adding a .gitignore, I don’t think I did it right though.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
you are on the correct path!
Your .gitignore
file should include the relative path to the database file. For example, if your database is named db.sqlite3
and located in the project root, your .gitignore
should look like this:
db.sqlite3
If the database is inside a folder, include the folder in the path:
path/to/db.sqlite3
.gitignore
is WorkingAfter setting up .gitignore
, test to ensure Git ignores the database file:
git status
The database file should no longer appear in the list of changes.
Hey Mark! 👋
Actually using the .gitignore
file is the right way to exclude your database file from being updated when syncing your repository.
What you could do is, you can add the database file’s name or path to your .gitignore
file. And then if the database is already tracked by Git, .gitignore
won’t take effect until you remove it from Git’s index. Run the following commands in your repository directory locally on your laptop:
git rm --cached db.sqlite3
git commit -m "Stop tracking the database file"
This removes the database from version control but keeps it on your Droplet.
Now, when you sync your files, Git will no longer update or overwrite the db.sqlite3
file on your Droplet.
Let me know if this works!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.