Git for Non-Developers: Version Control for Your Scripts and Macros


Hello again, tech enthusiasts! 👋

Does your “Scripts” folder look like this? report.py, report_v2.py, report_final.py, report_final_REAL.py. We have all been there.

Then one day your script stops working. You changed something last week, but you do not remember what. Which file was the good one?

There is a better way. It is called Git. Developers use it every day, but it is just as useful for office people with a few scripts and macros. Today you will learn the basics in about 15 minutes.

What you need

  • A computer with Windows, Mac or Linux
  • Git, free from https://git-scm.com
  • A folder with your scripts (Python, VBA, or anything that is text)

Step 1: Understand the idea

Version control is like a photo album for your files. Every time you are happy with your work, you take a photo. Git calls this photo a commit. Later, you can look at any old photo and bring back the file exactly as it was.

The album lives inside your folder, in a hidden folder called .git. This folder is called a repository (or “repo”).

Step 2: Install and set up Git

Download Git from the homepage and install it with the default options. On Windows, this also gives you a program called Git Bash. We will type our commands there.

Tell Git your name and email once. Git writes them on every commit, so you know who made each change.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Step 3: Start a repository

Go to your scripts folder and start the album:

cd ~/Documents/Scripts
git init

That is it. Your folder is now a Git repository.

Step 4: Keep data files out with .gitignore

Your scripts are small text files. But your folder may also have big data files like sales.xlsx or invoices.csv. These change all the time and may contain private data. We do not want them in the album.

Create a file named .gitignore in the folder. Each line is a pattern for files Git should ignore:

# Data files
*.xlsx
*.xls
*.csv
Reports/

# Python cache
__pycache__/

Step 5: Make your first commit

Saving a version has two parts. First you add the files you want in the photo. Then you commit with a short message.

git add .
git commit -m "First version of my report scripts"

The dot means “everything in this folder” (except ignored files). To check what Git sees first, use:

git status

From now on, after every working change, repeat git add and git commit.

Step 6: Look at your history

To see all your commits:

git log --oneline

You get something like this:

4c1a9e2 Add VAT column to invoice script
b73f0d1 Fix date format in monthly report
a12e5c8 First version of my report scripts

The code at the start of each line is the commit’s ID. You use it to go back in time.

Step 7: Bring back an old version

Your report script broke after the VAT change. You want the version from commit b73f0d1. Run:

git restore --source=b73f0d1 report.py

Now report.py is exactly as it was in that commit. If it works, commit it again with a message like “Go back to report before VAT change”. Your history keeps both versions. Nothing is lost.

Step 8: Track your Excel macros

Here is a problem. VBA macros live inside the .xlsm file. Git cannot see inside it well, and we ignore Excel files anyway.

The solution: export each macro module as a text file.

  1. Open your workbook and press Alt + F11 to open the VBA editor.
  2. In the left panel, right-click a module, for example Module1.
  3. Click Export File… and save it in your scripts folder as Module1.bas.
  4. Do the same for other modules. Class modules save as .cls, forms as .frm.

A .bas file is plain text, so Git can show exactly which lines changed. To bring an old macro back, restore the .bas file with Git, then in the VBA editor use File > Import File….

Make it a habit: export, then commit.

git add Module1.bas
git commit -m "Monthly summary macro: add totals row"

Common problems

  • “git is not recognized” → Close and reopen your terminal after installing. On Windows, use Git Bash.
  • “Please tell me who you are” → You skipped Step 2. Run the two git config commands.
  • A data file is still tracked after adding it to .gitignore → Git keeps tracking files it already knows. Run git rm --cached sales.xlsx, then commit.

Wrap-up

With four commands (init, add, commit, log) and one rescue command (restore), you never need report_final_REAL.py again. Your folder stays clean, and every old version is one command away.

Next idea: put your repository on a USB disk or a private online service as a second copy. Then your scripts are safe even if your laptop is not.