Untitled

By Beige Lizard, 5 Days ago, written in Plain Text, viewed 13 times.
URL http://pb.stoleyour.com/view/c84a8f99 Embed
Download Paste or View RawExpand paste to full width of browser
  1. # --- CONFIGURATION ---
  2. $SourceParentFolder = "C:\Path\To\Your\Local\MainFolder" # The folder containing the folders you want to upload
  3. $GitHubUsername     = "YourGitHubUsername"
  4. $RepoName           = "YourTargetRepoName"
  5. $GitHubToken        = "ghp_YourPersonalAccessToken" # Keep this secure!
  6. $Branch             = "main"
  7. # ---------------------
  8.  
  9. # Construct the authenticated remote URL
  10. $RemoteUrl = "https://$GitHubUsername`:$GitHubToken@github.com/$GitHubUsername/$RepoName.git"
  11.  
  12. # Change location to the parent folder
  13. Set-Location -Path $SourceParentFolder
  14.  
  15. # Get all directories inside the parent folder
  16. $Folders = Get-ChildItem -Directory
  17.  
  18. foreach ($Folder in $Folders) {
  19.     Write-Host "Processing folder: $($Folder.Name)" -ForegroundColor Cyan
  20.    
  21.     # Move into the specific subfolder
  22.     Set-Location $Folder.FullName
  23.  
  24.     # Initialize git if it hasn't been already
  25.     if (-not (Test-Path ".git")) {
  26.         git init -b $Branch
  27.         git remote add origin $RemoteUrl
  28.     } else {
  29.         # If remote already exists, update it to ensure token is current
  30.         git remote set-url origin $RemoteUrl
  31.     }
  32.  
  33.     # Stage all files, commit, and push
  34.     git add .
  35.     git commit -m "Automated upload of $($Folder.Name) via PowerShell"
  36.    
  37.     # Push to the repository
  38.     # Note: This pushes the contents of the folder to the repo.
  39.     # If you want each folder to be a subfolder in the SAME repo, see the note below.
  40.     git push -u origin $Branch
  41.  
  42.     Write-Host "Successfully pushed $($Folder.Name)" -ForegroundColor Green
  43. }
  44.  
  45. # Return to parent directory
  46. Set-Location $SourceParentFolder

Reply to "Untitled"

Here you can reply to the paste above