liveBook · Manning

Git

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

Git is a distributed version control system for tracking changes to files and coordinating work across repositories.

Git supports a practical workflow for keeping automation code in a local repository, recording snapshots of selected files, and synchronizing them to a remote GitHub repository. A repository is initialized in the module directory; files must then be explicitly added, committed, placed on the main branch, connected to a remote, and pushed. This separates files merely present in a folder from files tracked as repository content. section 12.2.1

Git can also be treated as a deployment dependency. An installation script can test for the Git executable, install it through an operating-system-appropriate package manager when absent, clone a remote repository, and expose its PowerShell module through a symbolic link in a PSModulePath location. Checking the executable first makes the installation repeatable rather than assuming every team machine is already prepared. section 12.2.3

A minimal publish-and-share sequence is:

  • Initialize the current module folder with git init, which creates the .git configuration directory. section 12.2.1
  • Stage intended content with git add ., then create a snapshot with git commit -m "first commit". section 12.2.1
  • Rename the local branch to main, create or connect a GitHub remote, and push main to establish remote tracking. section 12.2.1
  • Use a private GitHub repository when team access should be limited to invited contributors. section 12.2.1

Configure Git during a Windows installation

A PowerShell installer can install Git with Chocolatey, create an alias to git.exe, enable automatic CRLF-to-LF conversion at system scope, and set the user's default initial branch. Applying the line-ending setting after installation matters because Chocolatey's install parameters may be ignored when an existing Git installation is detected and upgraded or skipped. section 11.4.1

Listing 11.3 git-install.ps1
param(
    $branch
)
choco install git.install -y                        #1
 
$alias = @{                                         #2
    Name = 'git'
    Value = (Join-Path $Env:ProgramFiles 'Git\bin\git.exe')
}
New-Alias @alias -force
 
git config --system core.autocrlf true              #3
 
git config --global init.defaultBranch $branch      #4

This installer keeps package installation and Git configuration together: install Git, make git available in the session, normalize line endings, and choose the initial branch name. section 11.4.1

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Walks through installation, configuration, initialization, staging, committing, remote setup, pushing, and executable checks.
Examples
Uses a Git installer, a PoshAutomator module repository, and a cross-platform module installation script.
What it assumes
Assumes PowerShell and package-manager use while providing command-level Git installation and repository workflows.
What you can do after
Operate/configure it to install Git, configure defaults, publish module files, and sync them from GitHub.
How it connects
Connects Git with GitHub, Chocolatey, package managers, PowerShell modules, symbolic links, and PSModulePath.

Also explained in

Compare how 8 books explain git →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.