-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-github-setup.sh
More file actions
98 lines (76 loc) · 2.77 KB
/
git-github-setup.sh
File metadata and controls
98 lines (76 loc) · 2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
echo "🧹 Cleaning up old Git and GitHub configuration..."
# Backup old Git config if exists
if [ -f "$HOME/.gitconfig" ]; then
cp "$HOME/.gitconfig" "$HOME/.gitconfig.backup.$(date +%s)"
echo "🗃️ Existing Git config backed up."
fi
# Remove global git config settings
git config --global --unset-all user.name 2>/dev/null
git config --global --unset-all user.email 2>/dev/null
rm -f "$HOME/.gitconfig"
# Remove GitHub CLI auth data
if command -v gh >/dev/null 2>&1; then
gh auth logout -h github.com --yes
rm -rf ~/.config/gh
echo "🔓 GitHub CLI auth cleaned."
fi
# Optional: clean Git credentials cache
rm -f ~/.git-credentials
git config --global --unset credential.helper 2>/dev/null
echo "🧼 All previous configs cleaned! Proceeding to new setup..."
# 1. Ask for GitHub username
read -rp "🧑 Enter your GitHub username: " github_user
# 2. Ask for GitHub email
read -rp "📧 Enter your GitHub email: " github_email
# 3. Set up Git config
git config --global user.name "$github_user"
git config --global user.email "$github_email"
echo "✅ Git global config updated!"
# 4. Detect installed browsers
echo "🌐 Detecting installed browsers..."
browsers=()
commands=("firefox" "google-chrome" "chromium" "brave-browser" "microsoft-edge" "vivaldi")
for cmd in "${commands[@]}"; do
if command -v $cmd >/dev/null 2>&1; then
browsers+=("$cmd")
fi
done
if [ ${#browsers[@]} -eq 0 ]; then
echo "❌ No supported browsers found!"
exit 1
fi
echo "💻 Available browsers:"
for i in "${!browsers[@]}"; do
echo "$((i+1)). ${browsers[$i]}"
done
read -rp "📦 Select browser number to use for GitHub login: " browser_choice
browser_index=$((browser_choice - 1))
selected_browser="${browsers[$browser_index]}"
echo "🖱️ You selected: $selected_browser"
# 5. GitHub authentication using gh CLI
if ! command -v gh >/dev/null 2>&1; then
echo "⚠️ GitHub CLI (gh) not found! Installing..."
sudo apt update && sudo apt install gh -y
fi
echo "🔐 Logging into GitHub..."
BROWSER="$selected_browser" gh auth login --hostname github.com --web
if [ $? -ne 0 ]; then
echo "❌ GitHub authentication failed."
exit 1
else
echo "✅ GitHub successfully authenticated!"
fi
# 6. Optional: confirm setup with test repo
read -rp "📁 Do you want to create and push a test repo to GitHub? (y/n): " test_repo
if [[ "$test_repo" == "y" || "$test_repo" == "Y" ]]; then
mkdir test-git-setup && cd test-git-setup || exit
git init
echo "# Test Repo" > README.md
git add README.md
git commit -m "Initial commit"
gh repo create test-git-setup --private --source=. --remote=origin --push
echo "🚀 Test repository pushed to GitHub!"
else
echo "🎉 All done! Git and GitHub are now fully cleaned and configured."
fi