If you have ever saved a file as report_v2_final_FINAL.xlsx, you already understand why version control exists. Git does the same job properly: it remembers every version of your work, who changed what and why and lets you undo almost anything. This guide walks through the ideas in the order you meet them, from your first save to your first pull request.

This blog explains many git functions / commands and how to use them, but I want to emphasize that web-based platforms like GitHub and GitLab already have built-in functionalities that make these things easier (instead of typing a command in terminal, you just click a button in your platform).


Why version control exists

Without it, history lives in file names. You end up with script_v1.py, script_v2_final.py and a nagging fear of deleting the wrong one. Version control replaces that with a proper log: every change is recorded with an author, a time and a short explanation.

Git is the most widely used version control system. Linus Torvalds created it in 2005, and it is distributed: every person has a full copy of the project history on their own machine. That means you can work offline and branching (more on that below) is fast and cheap.

A repository, or repo, is the project folder plus a hidden .git folder where Git keeps all that history.


Two places your code lives

Git works across two locations:

  • Local: the copy on your own computer. You edit, test and record history here first.
  • Remote: a copy on a server such as GitHub or GitLab. It is the shared source of truth for your team.

To start on an existing project, you clone it:

Bash
git clone https://github.com/example-user/project-name.git

That downloads the files, the full history and every branch into a new local repo.


The three-step habit: save, stage, commit

This is the loop you will repeat hundreds of times.

  1. Save. Edit in your editor and save as normal. The file changes on disk, but Git has not recorded anything yet.
  2. Stage. Choose which saved changes belong in the next snapshot with git add. This is the framing step: you can add or remove things until the picture looks right.
  3. Commit. Record the snapshot in history, with a message. Each commit gets a unique ID (a hash), an author and a timestamp.
Bash
git add index.html          # stage one file
git add .                   # or stage everything that changed
git commit -m 'Add your commit message here'

Two habits make history useful later. Commit small, related changes together, and write a message that says what changed and why. 'Fix join that dropped null customers' beats 'updates'. The staging step exists so you can split a messy afternoon into clean commits instead of one lump.


Branches: a safe place to experiment

The main branch is the default line of history and by convention it holds the version that works. A branch is a lightweight pointer to a commit. Create one and you get your own line of work where nothing you do touches main.

Bash
git switch -c your-branch-name

That creates the feature branch and moves you onto it in one step. From here, every save, add and commit lands on your-branch-name only.

YAML
main:      C1 ── C2 ─────────────── M
                  \                 /
feature:           F1 ── F2 ───────┘

Branching is why teams can work in parallel: ten people, ten features, one stable main.


Sharing your work: push and pull

So far everything is on your machine. Two commands move commits between local and remote:

  • Push sends your local commits up to the remote so others can see them.
  • Pull downloads commits from the remote and merges them into your current branch. Do it regularly to stay in step with teammates.
Bash
git push origin feature-login-page
git pull origin main

Merging: bringing the work home

When the feature (branch) is finished and tested, merge it into main:

Bash
git switch main
git pull origin main
git merge feature-login-page

Updating (pulling) main before you merge means you combine your work with the latest version, not an old one.

Sometimes two people change the same lines. Git cannot guess which version should win, so it pauses and marks the clash in the file. That is a merge conflict. Open the file, keep the lines you want, delete the conflict markers, stage the file and commit.

On a team you will usually merge through a pull request on GitHub rather than the command line, so a colleague can review the change first. The result is the same.


Contributing to projects you don't own

For open-source projects you cannot push directly. The pattern is a fork: a server-side copy of the repo under your own account. A clone copies a repo to your computer; a fork copies it to the server.

  1. Fork the project on GitHub.
  2. Clone your fork to your machine.
  3. Create a branch, for example git switch -c your-branch.
  4. Edit, save, stage and commit.
  5. Push the branch to your fork.
  6. Open a pull request asking the owners to merge your branch into theirs.

Where this shows up in data work

Git is not only for software. Analytics and data engineering projects lean on it too. In dbt, for instance, you develop a change on your own branch, check it in a development environment, then merge it into main so the scheduled production jobs pick it up. It is the same loop as above: branch, commit, push and merge.

The best way to learn it is to make a throwaway repo, break things on a branch and merge them back. Nothing teaches merge conflicts like causing one on purpose.


Cheat sheet

Command What it does Example
clone Copies a remote repo to your computer git clone <url>
add Stages changes for the next commit git add index.html
commit Records staged changes in history git commit -m 'message'
branch Creates a separate line of development git branch <name>
switch Moves you onto a branch git switch <name>
push Uploads local commits to the remote git push origin <branch>
pull Downloads remote commits and merges them git pull origin main
merge Combines one branch into another git merge <feature>