206 lines
5.2 KiB
Batchfile
206 lines
5.2 KiB
Batchfile
@echo off
|
|
REM Git Credential Setup for Windows
|
|
REM Batch file version for Command Prompt users
|
|
|
|
echo.
|
|
echo =================================
|
|
echo 🔐 Git Credential Setup for Windows
|
|
echo =================================
|
|
echo.
|
|
|
|
REM Check if Git is installed
|
|
git --version >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo ❌ Error: Git is not installed
|
|
echo.
|
|
echo Please install Git for Windows:
|
|
echo Download: https://gitforwindows.org/
|
|
echo Or via winget: winget install --id Git.Git -e --source winget
|
|
echo.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo ✅ Git found:
|
|
git --version
|
|
echo.
|
|
|
|
REM Show current Git config
|
|
echo 📋 Current Git Configuration:
|
|
echo User Name:
|
|
git config --global user.name
|
|
echo User Email:
|
|
git config --global user.email
|
|
echo Credential Helper:
|
|
git config --global credential.helper
|
|
echo.
|
|
|
|
REM Check if we're in a Git repository
|
|
if exist .git (
|
|
echo 📁 Current Repository:
|
|
echo Remote URL:
|
|
git remote get-url origin
|
|
echo.
|
|
)
|
|
|
|
echo 🔧 Git Credential Setup Options:
|
|
echo 1. Git Credential Manager (Recommended)
|
|
echo 2. Personal Access Token
|
|
echo 3. SSH Keys (Most Secure)
|
|
echo 4. VS Code Integration
|
|
echo 5. Store Credentials (Less Secure)
|
|
echo.
|
|
|
|
set /p choice="Choose your preferred method (1-5): "
|
|
|
|
if "%choice%"=="1" goto :gcm_setup
|
|
if "%choice%"=="2" goto :pat_setup
|
|
if "%choice%"=="3" goto :ssh_setup
|
|
if "%choice%"=="4" goto :vscode_setup
|
|
if "%choice%"=="5" goto :store_setup
|
|
|
|
echo ❌ Invalid choice. Please run the script again.
|
|
pause
|
|
exit /b 1
|
|
|
|
:gcm_setup
|
|
echo.
|
|
echo 🔑 Setting up Git Credential Manager...
|
|
echo.
|
|
|
|
REM Check if GCM is installed
|
|
git-credential-manager --version >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo ⚠️ Git Credential Manager not found
|
|
echo.
|
|
echo Installing Git Credential Manager...
|
|
echo.
|
|
|
|
REM Try winget first
|
|
winget install --id GitHub.GitHubDesktop -e --source winget --silent
|
|
if %errorlevel% neq 0 (
|
|
echo Winget failed. Please install manually:
|
|
echo Download: https://github.com/git-ecosystem/git-credential-manager/releases/latest
|
|
echo Or install GitHub Desktop which includes GCM
|
|
pause
|
|
exit /b 1
|
|
)
|
|
echo ✅ GitHub Desktop (includes GCM) installed
|
|
)
|
|
|
|
REM Configure Git to use GCM
|
|
echo.
|
|
echo Configuring Git to use GCM...
|
|
git config --global credential.helper manager
|
|
echo ✅ GCM configured as credential helper
|
|
echo.
|
|
echo Next time you push/pull, GCM will open a browser for authentication
|
|
echo and securely store your credentials.
|
|
goto :end
|
|
|
|
:pat_setup
|
|
echo.
|
|
echo 🔑 Setting up Personal Access Token...
|
|
echo.
|
|
|
|
echo For git.d-popov.com, you'll need to:
|
|
echo 1. Go to your Git server web interface
|
|
echo 2. Generate a Personal Access Token
|
|
echo 3. Use your username + token as password
|
|
echo.
|
|
|
|
REM Configure Git to store credentials
|
|
git config --global credential.helper store
|
|
echo ✅ Git configured to store credentials
|
|
echo.
|
|
echo Next time you push/pull:
|
|
echo - Username: Your Git username
|
|
echo - Password: [your personal access token]
|
|
echo - Git will remember these credentials
|
|
goto :end
|
|
|
|
:ssh_setup
|
|
echo.
|
|
echo 🔐 Setting up SSH Keys...
|
|
echo.
|
|
|
|
if exist "%USERPROFILE%\.ssh\id_ed25519" (
|
|
echo ✅ SSH key already exists
|
|
) else (
|
|
echo Generating new SSH key...
|
|
ssh-keygen -t ed25519 -C "git-credentials" -f "%USERPROFILE%\.ssh\id_ed25519" -N ""
|
|
echo ✅ SSH key generated
|
|
)
|
|
|
|
echo.
|
|
echo 📋 SSH Public Key (add this to your Git server):
|
|
echo ----------------------------------------
|
|
type "%USERPROFILE%\.ssh\id_ed25519.pub"
|
|
echo ----------------------------------------
|
|
echo.
|
|
echo Next steps:
|
|
echo 1. Copy the public key above
|
|
echo 2. Add it to your Git server (git.d-popov.com)
|
|
echo 3. Test SSH connection: ssh -T git@git.d-popov.com
|
|
echo.
|
|
|
|
REM Ask if user wants to change remote URL to SSH
|
|
set /p change_remote="Change remote URL to SSH? (y/n): "
|
|
if /i "%change_remote%"=="y" (
|
|
for /f "tokens=*" %%i in ('git remote get-url origin') do set current_url=%%i
|
|
set ssh_url=%current_url:https://git.d-popov.com/=git@git.d-popov.com:%
|
|
git remote set-url origin "%ssh_url%"
|
|
echo ✅ Remote URL changed to SSH: %ssh_url%
|
|
)
|
|
goto :end
|
|
|
|
:vscode_setup
|
|
echo.
|
|
echo 💻 Setting up VS Code Git Integration...
|
|
echo.
|
|
|
|
REM Configure VS Code as credential helper
|
|
git config --global credential.helper vscode
|
|
echo ✅ VS Code configured as credential helper
|
|
echo.
|
|
echo Next time you use Git in VS Code:
|
|
echo - VS Code will prompt for credentials
|
|
echo - Choose 'Save' to store them
|
|
echo - Credentials are stored securely
|
|
goto :end
|
|
|
|
:store_setup
|
|
echo.
|
|
echo 💾 Setting up credential storage...
|
|
echo.
|
|
|
|
echo ⚠️ WARNING: This stores credentials in plain text!
|
|
echo This is less secure than other methods.
|
|
echo.
|
|
|
|
set /p confirm="Continue anyway? (y/n): "
|
|
if /i not "%confirm%"=="y" goto :end
|
|
|
|
git config --global credential.helper store
|
|
echo ✅ Git configured to store credentials
|
|
echo.
|
|
echo Your credentials will be stored in plain text.
|
|
echo Make sure your computer is secure!
|
|
goto :end
|
|
|
|
:end
|
|
echo.
|
|
echo 🎉 Git credential setup complete!
|
|
echo.
|
|
echo 📖 Additional Resources:
|
|
echo - Git Documentation: https://git-scm.com/doc
|
|
echo - GCM Documentation: https://aka.ms/gcm
|
|
echo - SSH Key Guide: https://docs.github.com/en/authentication/connecting-to-github-with-ssh
|
|
echo.
|
|
echo 🧪 Test your setup:
|
|
echo git fetch
|
|
echo git pull
|
|
echo git push
|
|
echo.
|
|
pause
|