How to keep development files synced

When I develop a website I create it locally and I use the local information for the database for example (connect to localhost…). When I put it online, I have to change this info, of course, but what if I have to make some changes to the online version?

What’s the fastest way to do this? Work on the local version and then change some lines and put them online? Work directly on the online files?

I don’t know if my point is clear, I hope so…