Lesson 1 of 7 · Git for DBAs

What Is Git

What Git is, the problem it solves, DBA life before it, why DBAs need it, and the essentials to learn.

Beginner 6 sections 4 min read

What Git is

Git is a version control system: it records every change to a set of files, who made it, when, and why, so you can see the full history, compare versions, undo mistakes, and let many people work on the same files without overwriting each other.

Linus Torvalds, yes, the same person who created Linux, built Git in 2005 to manage the source code of the Linux kernel, one of the largest collaborative software projects in the world. It's now used by almost every software team, and for much more than application code: SQL scripts, infrastructure code, configuration files, and documentation all live in Git.

A folder tracked by Git is called a repository, or repo. Each time you save a set of changes into it, you make a commit: a snapshot of the files at that moment, with a message explaining the change. The commits together form the project's history.

The problem Git solves

Any file that changes over time, and especially one that several people change, raises the same questions:

  • What changed? Which lines are different from last week's version?
  • Who changed it, and why? Was this a deliberate fix or a mistake?
  • Which version is current? Which copy is the one running in production?
  • How do we undo it? Can we get back to the version that worked?
  • How do we work together? How do two people edit the same file without losing each other's work?

Git answers all of them. Every version of every file is kept, every change is labeled with its author, date, and reason, and changes from different people are combined safely.

DBA life before Git

For years, most DBA teams kept their scripts the way many still do: in shared folders, email attachments, and personal desktops.

BEFORE: SHARED DRIVE create_tables.sqlcreate_tables_v2.sqlcreate_tables_final.sqlcreate_tables_final_FIXED.sqlcreate_tables_kofi_copy.sql Which one ran in production? Nobody's sure. WITH GIT: ONE FILE, FULL HISTORY create_tables.sql Increase region column sizeYaw · today Add index on orders dateKofi · last week Add orders tableAma · last month Every version kept, with who, when, and why.

That led to familiar problems:

  • Too many copies. Files named _final, _final2, and _FIXED, with nobody sure which one was right.
  • No history. When a script changed, the old version was gone, along with any record of why it changed.
  • Overwritten work. Two DBAs edited the same script, and the last one to save won.
  • No review. Changes ran in production straight from someone's desktop, without a second pair of eyes.
  • Knowledge walked out the door. When a DBA left, their scripts, and the reasons behind them, often went too.
  • No audit trail. Auditors asking "who changed this, and who approved it?" got answers pieced together from emails and tickets.

Why DBAs need Git

Everything is code now
SQL scripts, schema migrations, Terraform, Ansible playbooks, pipeline definitions, and runbooks are all text files, and they all belong in Git.
It's the start of every pipeline
CI/CD pipelines are triggered by changes in Git. Without Git, there's no automated testing or deployment of database changes.
Peer review
Changes are reviewed in pull requests before they're merged, catching mistakes before they reach production.
A built-in audit trail
Every change has an author, a date, a message, and often a linked ticket and approval, which is exactly what auditors ask for.
Safe experiments and easy undo
Try changes on a branch without affecting anyone else, and go back to any earlier version when something goes wrong.
Working with other teams
Developers, infrastructure, and security teams already use Git. A DBA who uses it works in the same place, in the same way, as everyone else.

Git essentials for DBAs

You don't need to know all of Git to be productive. These essentials cover almost everything a DBA does day to day, and the rest of this module teaches each one:

SkillWhat it lets you doCovered in
Commit changesSave a snapshot of your work with a clear messageHow Git Works
Read history and differencesSee what changed, when, by whom, and whyHow Git Works
Branch and mergeWork on a change without affecting others, then combine itHow Git Works
Push, pull, and cloneShare work through a remote repositoryLocal and Remote Repositories
Pull requestsPropose, review, and approve changesLocal and Remote Repositories
Use Git from VS CodeDo all of the above without memorizing commandsUsing Git
Keep secrets outNever commit passwords or keysGit Best Practices

Key takeaways

  • Git is a version control system that records every change: what, who, when, and why.
  • A repository holds the files and their history; a commit is a snapshot with a message.
  • Before Git, DBA scripts lived in shared folders and emails, with duplicate copies, lost history, overwritten work, and no review.
  • DBAs need Git because everything is code, pipelines start from Git, and it gives review, audit trails, and easy undo.
  • A handful of essentials, commit, history, branches, push and pull, and pull requests, cover most of a DBA's work.

The Git logo on this module's card is by Jason Long, used under the Creative Commons Attribution 3.0 license.