-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_github.sh
More file actions
68 lines (55 loc) · 1.4 KB
/
update_github.sh
File metadata and controls
68 lines (55 loc) · 1.4 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
61
62
63
64
65
66
67
#!/bin/bash
# Script to update project to GitHub
# Usage: ./update_github.sh "Your commit message"
COMMIT_MESSAGE=${1:-"Update portfolio website with new features"}
echo "=== Updating Project to GitHub ==="
# Check if git is initialized
if [ ! -d .git ]; then
echo "Git repository not found. Initializing..."
git init
fi
# Add .gitignore if not already tracked
if ! git ls-files --error-unmatch .gitignore >/dev/null 2>&1; then
echo "Adding .gitignore..."
git add .gitignore
git commit -m "Add .gitignore"
fi
# Stage all changes
echo ""
echo "Staging all changes..."
git add .
# Show status
echo ""
echo "Current status:"
git status --short
# Commit changes
echo ""
echo "Committing changes..."
git commit -m "$COMMIT_MESSAGE"
if [ $? -eq 0 ]; then
echo ""
echo "Pushing to GitHub..."
# Get current branch
BRANCH=$(git branch --show-current)
if [ -z "$BRANCH" ]; then
BRANCH="main"
fi
# Push to origin
git push origin "$BRANCH"
if [ $? -eq 0 ]; then
echo ""
echo "=== Successfully updated to GitHub! ==="
echo "Branch: $BRANCH"
else
echo ""
echo "=== Push failed ==="
echo "You may need to set upstream branch:"
echo "git push -u origin $BRANCH"
fi
else
echo ""
echo "=== Commit failed ==="
echo "No changes to commit or commit message required."
fi
echo ""
echo "Done!"