# --- CONFIGURATION ---
$SourceParentFolder = "C:\Path\To\Your\Local\MainFolder" # The folder containing the folders you want to upload
$GitHubUsername = "YourGitHubUsername"
$RepoName = "YourTargetRepoName"
$GitHubToken = "ghp_YourPersonalAccessToken" # Keep this secure!
$Branch = "main"
# ---------------------
# Construct the authenticated remote URL
$RemoteUrl = "https://$GitHubUsername`:$GitHubToken@github.com/$GitHubUsername/$RepoName.git"
# Change location to the parent folder
Set-Location -Path $SourceParentFolder
# Get all directories inside the parent folder
$Folders = Get-ChildItem -Directory
foreach ($Folder in $Folders) {
Write-Host "Processing folder: $($Folder.Name)" -ForegroundColor Cyan
# Move into the specific subfolder
Set-Location $Folder.FullName
# Initialize git if it hasn't been already
if (-not (Test-Path ".git")) {
git init -b $Branch
git remote add origin $RemoteUrl
} else {
# If remote already exists, update it to ensure token is current
git remote set-url origin $RemoteUrl
}
# Stage all files, commit, and push
git add .
git commit -m "Automated upload of $($Folder.Name) via PowerShell"
# Push to the repository
# Note: This pushes the contents of the folder to the repo.
# If you want each folder to be a subfolder in the SAME repo, see the note below.
git push -u origin $Branch
Write-Host "Successfully pushed $($Folder.Name)" -ForegroundColor Green
}
# Return to parent directory
Set-Location $SourceParentFolder
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"text\/x-go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"mysql","xml":"xml","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","ecmascript":"javascript","groovy":"text\/x-groovy","haskell":"text\/x-haskell","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mysql":"mysql","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"plsql","properties":"text\/x-properties","scheme":"text\/x-scheme","vb":"text\/vbscript","vbnet":"text\/vbscript","verilog":"text\/x-verilog","yaml":"text\/x-yaml"}