Skip to content

Instantly share code, notes, and snippets.

@azurekid
Created May 10, 2023 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azurekid/c5ff1e16729afd93b24413adf1abe009 to your computer and use it in GitHub Desktop.
Save azurekid/c5ff1e16729afd93b24413adf1abe009 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$GitBranch,
[Parameter(Mandatory = $false)]
[string]$CommitMessage = 'rebuild repository',
[Parameter(Mandatory = $false)]
[switch]$Force
)
Write-Host "USAGE OF THIS SCRIPT IS ON YOUR OWN RISK" -ForegroundColor 'Red'
Write-Host "- I AM NOT RESPONSIBLE FOR ANY LOSS OF DATA-" -ForegroundColor 'Red'
if ($Force) {
Write-Host "[-] Checking out current branch" -ForegroundColor 'Yellow'
git checkout --orphan (new-guid).guid
Write-Host "[-] Adding current files" -ForegroundColor 'Yellow'
git add .
Write-Host "[-] Adding commit message [$CommitMessage]" -ForegroundColor 'Yellow'
$null = git commit -m $CommitMessage
Write-Host "[-] Deleting current branch with the name [$GitBranch]" -ForegroundColor 'Red'
Write-Host "[-] To late now, branch [$GitBranch] is deleted" -ForegroundColor 'Red'
$null = git branch -D main
Write-Host "[-] Renaming branch to [$GitBranch]" -ForegroundColor 'Yellow'
$null = git branch -m main
Write-Host "pushing data to new branch" -ForegroundColor 'Yellow'
$null = git push -f origin $GitBranch
} else {
Write-Error "Use the '-Force' switch start use the function! 'Clear-GitHistory -GitBranch main -Force'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment