Learn › Git

Git for Windows Admins: Set Up Your First Automation Repo

Install Git on Windows, create a repo for your scripts, push it to GitHub and learn branches and pull requests. No coding background needed.

Beginner 12 min read Part 1 of 3
By Gopinath Karthikeyan · 29 Nov 2026

If your scripts live in C:\Scripts, on a shared drive and in three email attachments called final_v2_NEW.ps1, this guide is for you.

Git keeps every version of your scripts, shows who changed what and why, and lets you undo a bad change in seconds. It’s also the starting point for everything in this learning path: in Part 2 Jenkins will pull your scripts from Git, and in Part 3 Ansible playbooks from the same repo will manage your servers.

You don’t need to be a developer. If you can run commands in PowerShell, you can use Git.

What you need: a Windows 10/11 laptop or VM where you can install software, and a free GitHub account. About 45 minutes.

The 5 words you need first

Word What it means for an admin
Repository (repo) A folder that Git tracks – your scripts plus their full history
Commit A saved snapshot with a message, like “Add disk cleanup script”
Branch A safe copy to work on a change without touching the main version
Remote The copy of your repo on a server such as GitHub, shared with your team
Pull request (PR) A request to merge your branch into main, so someone can review it first

Step 1: install Git

Open PowerShell and check whether Git is already there:

git --version

If you see something like git version 2.x.x.windows.1, skip to Step 2. If PowerShell says the command isn’t recognised, install it with winget:

winget install --id Git.Git -e --source winget

Or download the installer from git-scm.com and accept the defaults. The default options also install Git Credential Manager, which handles your GitHub sign-in later.

Close and reopen PowerShell, then run git --version again.

Step 2: tell Git who you are

Every commit records a name and email. Set them once:

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

Check it:

git config --global --list

Use the same email as your GitHub account so your commits are linked to your profile. Keep work and personal accounts separate – don’t push company scripts to a personal GitHub.

Step 3: create your automation repo

We’ll build a lab repo called winops-lab that the next two parts reuse.

mkdir C:\Lab\winops-lab
cd C:\Lab\winops-lab
git init

Now create a folder layout that keeps each tool’s files apart:

mkdir scripts, ansible, jenkins
New-Item README.md -Value "# winops-lab`nScripts, Jenkins pipelines and Ansible playbooks for my Windows lab." | Out-Null
New-Item scripts\Get-DiskReport.ps1 | Out-Null

Your repo now looks like this:

winops-lab/
├── README.md
├── scripts/      PowerShell scripts
├── jenkins/      Jenkinsfiles (Part 2)
└── ansible/      playbooks and inventory (Part 3)

Add a first real script. Open scripts\Get-DiskReport.ps1 in Notepad or VS Code and paste:

# Lists each fixed drive with its free space
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
    Select-Object DeviceID,
        @{n='SizeGB'; e={[math]::Round($_.Size / 1GB, 1)}},
        @{n='FreeGB'; e={[math]::Round($_.FreeSpace / 1GB, 1)}},
        @{n='FreePct'; e={[math]::Round($_.FreeSpace / $_.Size * 100)}}

Test it: .\scripts\Get-DiskReport.ps1

Step 4: keep secrets out with .gitignore

This is the most important step for admins. Anything you commit stays in the history, even if you delete it later. Passwords, keys and server lists with real names must never go in.

Create a file called .gitignore in the repo root:

@"
# Secrets and local settings - never commit these
*.pfx
*.key
*.pem
*secret*
*password*
.env
credentials*.xml

# Output and logs
*.log
reports/
"@ | Set-Content .gitignore

Passwords belong in a vault or in Jenkins credentials (Part 2), not in scripts.

Step 5: your first commit

git status

git status is the command you’ll run most. It shows new and changed files in red (not yet staged).

git add .
git status
git commit -m "Add repo layout, disk report script and .gitignore"

After git add the files turn green (staged); git commit saves the snapshot. See your history with:

git log --oneline

Step 6: push to GitHub

  1. Sign in at github.com, click New repository.
  2. Name it winops-lab, choose Private, and don’t tick “Add a README” (you already have one).
  3. Click Create repository and copy the HTTPS address it shows.

Back in PowerShell (replace YOUR-USER):

git remote add origin https://github.com/YOUR-USER/winops-lab.git
git push -u origin main

The first push opens a browser window from Git Credential Manager – sign in to GitHub and approve. Refresh the GitHub page: your files are there.

Step 7: the daily routine – branch, commit, pull request

Never change main directly. Make every change on a branch, then merge it through a pull request. That’s how teams review scripts before they touch servers.

git switch -c add-free-space-warning

Edit scripts\Get-DiskReport.ps1 and add a warning at the end:

$low = Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
    Where-Object { $_.FreeSpace / $_.Size -lt 0.10 }
if ($low) { Write-Warning "Drives below 10% free: $($low.DeviceID -join ', ')" }

Commit and push the branch:

git add scripts\Get-DiskReport.ps1
git commit -m "Warn when a drive has less than 10% free"
git push -u origin add-free-space-warning

On GitHub you’ll see Compare & pull request. Click it, describe the change, then Merge pull request. Finally update your local main:

git switch main
git pull

That’s the loop you’ll repeat every day: branch → change → commit → push → pull request → merge → pull.

Undo cheat sheet

Situation Command
Throw away changes to one file (not committed yet) git restore scripts\Get-DiskReport.ps1
Unstage a file you added by mistake git restore --staged file.ps1
Fix the message of your last commit (not pushed yet) git commit --amend -m "Better message"
Undo a commit that’s already pushed – safely git revert <commit-id>
See what changed before committing git diff

git revert creates a new commit that reverses the old one, so the history stays honest. Avoid rewriting history on shared branches.

Common errors

  • git is not recognized – PowerShell was open before the install. Close it and open a new window.
  • rejected – fetch first when pushing – someone (or you, on GitHub) changed the branch. Run git pull, then push again.
  • Authentication failed – sign in again through the browser prompt; GitHub no longer accepts your account password on the command line.
  • Committed a password by mistake – change the password first (assume it’s leaked), then remove the file from the repo. Deleting it in a new commit doesn’t remove it from history.

FAQ

Do I need GitHub, or can I use Git without it? Git works fully offline on your laptop. GitHub (or GitLab, Bitbucket, Azure DevOps) is only needed to share the repo and to let tools like Jenkins fetch it.

Should admin scripts go in one repo or many? Start with one repo per team or platform, with folders per tool as above. Split later if a part grows its own release cycle.

Is GitHub Desktop or VS Code okay instead of commands? Yes. They run the same Git commands underneath. Learn the commands once so you understand what the buttons do.

What’s next

In Part 2 you’ll install Jenkins, connect it to this winops-lab repo and write a first pipeline (jenkins/Jenkinsfile) that checks every PowerShell script automatically – so a broken script never reaches a server.

Practise this topic

Test yourself with free questions on this topic – instant answers and explanations.

Start practice questions

GitGitHubPowerShellAutomationBeginnerWindows Admin

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn