# --- 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