What's the best way to clean up transaction log files in SQL Server?

I work with SQL Server but I’m still learning the more advanced stuff. I have this development database that’s pretty small, maybe a few GB, but somehow the transaction log file has grown huge and is taking up tons of disk space. I tried looking online but got confused with all the different methods people suggest. What’s the safest way to shrink or clean up these log files without breaking anything? I don’t want to mess up the database since it has some important test data that took time to set up. Should I be doing regular maintenance to prevent this from happening again?

first off, always back up your log before anything else! then try using dbcc shrinkfile. but be careful, overdoing it can lead to perf probs when it starts to grow again.

is your recovery model set to full? that could explain the huge log file. if you’re not doing log backups, switching to simple model might help. it could really solve your issue without risking your test data.

For development databases, first determine if transaction log backups are necessary. If the database is solely for testing and you can afford to lose some recovery options, consider switching to the Simple recovery model, which automatically truncates the log during checkpoints. If you require the Full recovery model, establish a maintenance plan for transaction log backups every 15 to 30 minutes during active periods. Once you have recent log backups, the space can be reused. After that, use DBCC SHRINKFILE to reclaim physical space, but avoid overusing this command as it can lead to fragmentation. The proper solution is implementing a backup routine to prevent future log file growth issues.