{"id":50,"date":"2024-07-28T20:15:00","date_gmt":"2024-07-28T17:15:00","guid":{"rendered":"https:\/\/fsaeed.blog\/?p=50"},"modified":"2026-10-31T00:18:53","modified_gmt":"2026-10-30T21:18:53","slug":"git-for-non-developers","status":"publish","type":"post","link":"https:\/\/fsaeed.blog\/index.php\/2024\/07\/28\/git-for-non-developers\/","title":{"rendered":"Git for Non-Developers: Version Control for Your Scripts and Macros"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello again, tech enthusiasts! \ud83d\udc4b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Does your &#8220;Scripts&#8221; folder look like this? <code>report.py<\/code>, <code>report_v2.py<\/code>, <code>report_final.py<\/code>, <code>report_final_REAL.py<\/code>. We have all been there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then one day your script stops working. You changed something last week, but you do not remember what. Which file was the good one?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is a better way. It is called <strong>Git<\/strong>. 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What you need<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A computer with Windows, Mac or Linux<\/li>\n\n\n<li>Git, free from <a href=\"https:\/\/git-scm.com\">https:\/\/git-scm.com<\/a><\/li>\n\n\n<li>A folder with your scripts (Python, VBA, or anything that is text)<\/li>\n\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Understand the idea<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Version control<\/strong> 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 <strong>commit<\/strong>. Later, you can look at any old photo and bring back the file exactly as it was.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The album lives inside your folder, in a hidden folder called <code>.git<\/code>. This folder is called a <strong>repository<\/strong> (or &#8220;repo&#8221;).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Install and set up Git<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Download Git from the homepage and install it with the default options. On Windows, this also gives you a program called <strong>Git Bash<\/strong>. We will type our commands there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tell Git your name and email once. Git writes them on every commit, so you know who made each change.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --global user.name \"Your Name\"\ngit config --global user.email \"you@example.com\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Start a repository<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Go to your scripts folder and start the album:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\/Documents\/Scripts\ngit init<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That is it. Your folder is now a Git repository.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Keep data files out with .gitignore<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your scripts are small text files. But your folder may also have big data files like <code>sales.xlsx<\/code> or <code>invoices.csv<\/code>. These change all the time and may contain private data. We do not want them in the album.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file named <code>.gitignore<\/code> in the folder. Each line is a pattern for files Git should ignore:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Data files\n*.xlsx\n*.xls\n*.csv\nReports\/\n\n# Python cache\n__pycache__\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Make your first commit<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Saving a version has two parts. First you <strong>add<\/strong> the files you want in the photo. Then you <strong>commit<\/strong> with a short message.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add .\ngit commit -m \"First version of my report scripts\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The dot means &#8220;everything in this folder&#8221; (except ignored files). To check what Git sees first, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">From now on, after every working change, repeat <code>git add<\/code> and <code>git commit<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Look at your history<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To see all your commits:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git log --oneline<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You get something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>4c1a9e2 Add VAT column to invoice script\nb73f0d1 Fix date format in monthly report\na12e5c8 First version of my report scripts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The code at the start of each line is the commit&#8217;s <strong>ID<\/strong>. You use it to go back in time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Bring back an old version<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your report script broke after the VAT change. You want the version from commit <code>b73f0d1<\/code>. Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git restore --source=b73f0d1 report.py<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now <code>report.py<\/code> is exactly as it was in that commit. If it works, commit it again with a message like &#8220;Go back to report before VAT change&#8221;. Your history keeps both versions. Nothing is lost.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Track your Excel macros<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a problem. VBA macros live <strong>inside<\/strong> the <code>.xlsm<\/code> file. Git cannot see inside it well, and we ignore Excel files anyway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution: export each macro module as a text file.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your workbook and press <strong>Alt + F11<\/strong> to open the VBA editor.<\/li>\n\n\n<li>In the left panel, right-click a module, for example <code>Module1<\/code>.<\/li>\n\n\n<li>Click <strong>Export File&#8230;<\/strong> and save it in your scripts folder as <code>Module1.bas<\/code>.<\/li>\n\n\n<li>Do the same for other modules. Class modules save as <code>.cls<\/code>, forms as <code>.frm<\/code>.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>.bas<\/code> file is plain text, so Git can show exactly which lines changed. To bring an old macro back, restore the <code>.bas<\/code> file with Git, then in the VBA editor use <strong>File &gt; Import File&#8230;<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make it a habit: export, then commit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add Module1.bas\ngit commit -m \"Monthly summary macro: add totals row\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Common problems<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>&#8220;git is not recognized&#8221;<\/strong> \u2192 Close and reopen your terminal after installing. On Windows, use Git Bash.<\/li>\n\n\n<li><strong>&#8220;Please tell me who you are&#8221;<\/strong> \u2192 You skipped Step 2. Run the two <code>git config<\/code> commands.<\/li>\n\n\n<li><strong>A data file is still tracked after adding it to .gitignore<\/strong> \u2192 Git keeps tracking files it already knows. Run <code>git rm --cached sales.xlsx<\/code>, then commit.<\/li>\n\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Wrap-up<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With four commands (<code>init<\/code>, <code>add<\/code>, <code>commit<\/code>, <code>log<\/code>) and one rescue command (<code>restore<\/code>), you never need <code>report_final_REAL.py<\/code> again. Your folder stays clean, and every old version is one command away.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use Git to keep every version of your scripts and Excel macros, so you can always go back to one that worked.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[23,25,12,9,24],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-git","tag-productivity","tag-python","tag-vba","tag-version-control"],"_links":{"self":[{"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":1,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/posts\/50\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsaeed.blog\/index.php\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}