-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGit-Copy.ps1
More file actions
52 lines (39 loc) · 1.27 KB
/
Git-Copy.ps1
File metadata and controls
52 lines (39 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.NOTES
RUNNING SCRIPTS CARRIES RISK. ALWAYS REVIEW SCRIPTS BEFORE RUNNING THEM ON YOUR SYSTEM.
IF IN DOUBT, COPY AND PASTE THE SCRIPT INTO A SERVICE LIKE CHATGPT AND ASK IF IT COULD BE HARMFUL.
.SYNOPSIS
Clone a git repo, using only the latest head.
Remove git history and re-initialise as a new repo.
.DESCRIPTION
Clone a git repo, using only the latest head.
Remove git history and re-initialise as a new repo.
Intended for using an existing repo as a template for a new project.
.PARAMETER RepoUrl
URL to the Git repo to use as template
.PARAMETER NewName
Name for the new folder containing the new copy of the repo
.NOTES
Author : Stuart Bell
License : MIT
Repository : https://github.com/stu-bell/powershell-scripts
.LINK
https://github.com/stu-bell/powershell-scripts
#>
param(
[Parameter(Mandatory=$true)]
[string]$RepoUrl,
[Parameter(Mandatory=$true)]
[string]$NewName
)
# Clone repo. --depth 1 avoids pulling the project history
Write-Host "Cloning $RepoUrl into $NewName..."
git clone --single-branch --depth 1 $RepoUrl $NewName
# Remove the cloned .git directory
Set-Location $NewName
Remove-Item -Path ".git" -Recurse -Force
# Initialise new repo
git init
git add .
git commit -m "Init from $RepoUrl"
Write-Host "Git copy complete"