-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_github.ps1
More file actions
61 lines (48 loc) · 1.77 KB
/
update_github.ps1
File metadata and controls
61 lines (48 loc) · 1.77 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
52
53
54
55
56
57
58
59
60
# Script to update project to GitHub
# Usage: .\update_github.ps1 "Your commit message"
param(
[string]$commitMessage = "Update portfolio website with new features"
)
Write-Host "=== Updating Project to GitHub ===" -ForegroundColor Cyan
# Check if git is initialized
if (-not (Test-Path .git)) {
Write-Host "Git repository not found. Initializing..." -ForegroundColor Yellow
git init
}
# Add .gitignore if not already added
if (-not (git ls-files --error-unmatch .gitignore 2>$null)) {
Write-Host "Adding .gitignore..." -ForegroundColor Yellow
git add .gitignore
git commit -m "Add .gitignore"
}
# Stage all changes
Write-Host "`nStaging all changes..." -ForegroundColor Yellow
git add .
# Show status
Write-Host "`nCurrent status:" -ForegroundColor Yellow
git status --short
# Commit changes
Write-Host "`nCommitting changes..." -ForegroundColor Yellow
git commit -m $commitMessage
if ($LASTEXITCODE -eq 0) {
Write-Host "`nPushing to GitHub..." -ForegroundColor Yellow
# Get current branch
$branch = git branch --show-current
if (-not $branch) {
$branch = "main"
}
# Push to origin
git push origin $branch
if ($LASTEXITCODE -eq 0) {
Write-Host "`n=== Successfully updated to GitHub! ===" -ForegroundColor Green
Write-Host "Branch: $branch" -ForegroundColor Green
} else {
Write-Host "`n=== Push failed ===" -ForegroundColor Red
Write-Host "You may need to set upstream branch:" -ForegroundColor Yellow
Write-Host "git push -u origin $branch" -ForegroundColor Yellow
}
} else {
Write-Host "`n=== Commit failed ===" -ForegroundColor Red
Write-Host "No changes to commit or commit message required." -ForegroundColor Yellow
}
Write-Host "`nDone!" -ForegroundColor Cyan