If you develop software either professionally or as a hobby using a modern version control package is a no brainer.
Even if you only work on hobby projects by yourself and nobody else ever gets to touch the source code or binary assets there is little excuse to not use version control for your projects. It doesn’t matter what version control package you happen to use, using the package effectively is universal issue.
Hopefully these guidelines that I’ve adopted over the past few decades, most of them learned through bitter experience rather than any useful guide or manual, will enhance your effective usage of version control. Never again be afraid to change a piece of code to test out an idea or worry about “losing the source code” years after you have worked on something.
- Never check-in anything at the end of the day.
- Ever.
- This rule is the Golden Rule.
- It is inviolable.
- You will completely regret having checked in last thing the previous night if you do.
- Check-in often.
- Don’t go weeks (or even days) between check-ins.
- Create a cheap branch to allow you to check-in without breaking the build.
- If you aren’t comfortable with branches, create temporary directories in the version control.
- Synchronize regularly.
- Synchronize.
- Synchronize.
- Synchronize.
- Your check-in procedure should be:
- Compile (if you cannot compile, why are you trying to check in?)
- Synchronize.
- Compile (if you cannot compile after synchronization, why are you trying to check in?)
- Check-in.
- Synchronize.
- Compile (if you cannot compile after all that, you have a merge error.)
- Run your unit tests or run the executable, whichever it is you do. (“It compiles, let’s ship it” is not a mantra for the development of robust software.)
- This will generally prevent about 99% of screw ups.
- It takes an extra minute or two.
- Build all platforms and configurations.
- Xoreax IncrediBuild works great for this. So do other distributed build systems.
- Make it your job to have the time necessary.
- Other programmers will thank you for not breaking their configuration or platform.
- The continuous integration server/build monkey is not a crutch for bad habits.
- Bad habits make the build monkey angry.
- Don’t use the build monkey to catch your compiler errors.
- An angry build monkey is not something you want to deal with.
- Don’t check-in then go for lunch, coffee, smoke, bathroom break, nap, etc.
- Wait for the automated e-mail from the continuous integration server/build monkey to be sent out to verify all is good in build land.
- You do have a continuous integration server/build monkey? Right?
- Don’t edit files without checking them out.
- Not even for “quick fixes.”
- If you are going to be editing a file to test something out, and just want to “try it”, check out the file to a new change list with the description “DO NOT CHECK-IN.”
- That way, if you do something stupid, you can easily tell which file you did the stupid thing in by performing a diff.
- You can instantly see how your source code differs from the one in version control.
- And if you find you do want to commit your changes, it is easy to determine which files you modified with your “quick fix.”
- Atomize your commits.
- Each one should be a discrete step in the development process that reproduces perfectly a singular change.
- Don’t check out dozens of files, complete a half-dozen tasks in your project plan then commit them all back in.
- Break it up.
- Commits are cheap.
- Mistakes aren’t.
- Don’t work outside of the version control directories.
- Configure your continuous integration server/build monkey to compile after every commit.
- If you think it should be in version control, put it there.You can always take it back out later.
Bonus Rule!
- See rule #1.