2022-11-17 20:13:00 +01:00
|
|
|
## The PowerShell Script *configure-git.ps1*
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2022-02-10 09:01:07 +01:00
|
|
|
This PowerShell script configures the user settings for Git.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
```powershell
|
2021-12-09 16:19:09 +01:00
|
|
|
configure-git.ps1 [[-FullName] <String>] [[-EmailAddress] <String>] [[-FavoriteEditor] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
-FullName <String>
|
|
|
|
Specifies the user's full name
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-EmailAddress <String>
|
|
|
|
Specifies the user's email address
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 2
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-FavoriteEditor <String>
|
|
|
|
Specifies the user's favorite text editor
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 3
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
```powershell
|
|
|
|
PS> ./configure-git
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Related Links
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
## Source Code
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Configures Git
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script configures the user settings for Git.
|
|
|
|
.PARAMETER FullName
|
|
|
|
Specifies the user's full name
|
|
|
|
.PARAMETER EmailAddress
|
|
|
|
Specifies the user's email address
|
|
|
|
.PARAMETER FavoriteEditor
|
|
|
|
Specifies the user's favorite text editor
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./configure-git
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param([string]$FullName = "", [string]$EmailAddress = "", [string]$FavoriteEditor = "")
|
|
|
|
|
|
|
|
try {
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
|
|
Write-Host "⏳ (1/6) Searching for Git executable... " -noNewline
|
|
|
|
& git --version
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
|
|
|
|
|
|
|
"⏳ (2/6) Asking for details..."
|
|
|
|
if ($FullName -eq "") { $FullName = read-host "Enter your full name" }
|
|
|
|
if ($EmailAddress -eq "") { $EmailAddress = read-host "Enter your e-mail address"}
|
|
|
|
if ($FavoriteEditor -eq "") { $FavoriteEditor = read-host "Enter your favorite text editor (atom,emacs,nano,subl,vi,vim,...)" }
|
|
|
|
|
|
|
|
"⏳ (3/6) Saving personal settings (name,email,editor)..."
|
|
|
|
& git config --global user.name $FullName
|
|
|
|
& git config --global user.email $EmailAddress
|
|
|
|
& git config --global core.editor $FavoriteEditor
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git config' failed with exit code $lastExitCode" }
|
|
|
|
|
|
|
|
"⏳ (4/6) Saving basic settings (autocrlf,symlinks,longpaths,etc.)..."
|
|
|
|
& git config --global core.autocrlf false # don't change newlines
|
|
|
|
& git config --global core.symlinks true # enable support for symbolic link files
|
|
|
|
& git config --global core.longpaths true # enable support for long file paths
|
|
|
|
& git config --global http.sslVerify false
|
|
|
|
& git config --global init.defaultBranch main # set the default branch name to 'main'
|
|
|
|
& git config --global merge.renamelimit 99999
|
|
|
|
& git config --global pull.rebase false
|
|
|
|
& git config --global fetch.parallel 0 # enable parallel fetching to improve the speed
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git config' failed with exit code $lastExitCode" }
|
|
|
|
|
|
|
|
"⏳ (5/6) Saving shortcuts (git co, git br, etc.)..."
|
|
|
|
& git config --global alias.co "checkout"
|
|
|
|
& git config --global alias.br "branch"
|
|
|
|
& git config --global alias.ci "commit"
|
|
|
|
& git config --global alias.st "status"
|
|
|
|
& git config --global alias.pl "pull --recurse-submodules"
|
|
|
|
& git config --global alias.ps "push"
|
|
|
|
& git config --global alias.mrg "merge --no-commit --no-ff"
|
|
|
|
& git config --global alias.chp "cherry-pick --no-commit"
|
|
|
|
& git config --global alias.ls "log -n20 --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an%Creset %C(green)%cr%Creset' --abbrev-commit"
|
|
|
|
& git config --global alias.smu "submodule update --init"
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git config' failed" }
|
|
|
|
|
|
|
|
"⏳ (6/6) Listing your Git settings..."
|
|
|
|
& git config --list
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git config --list' failed with exit code $lastExitCode" }
|
|
|
|
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
|
|
|
"✔️ configured Git in $Elapsed sec."
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber)): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2021-11-08 21:36:42 +01:00
|
|
|
*Generated by convert-ps2md.ps1 using the comment-based help of configure-git.ps1*
|