Skip to content

Instantly share code, notes, and snippets.

@EdoardoVignati
Last active July 6, 2023 08:18
Show Gist options
  • Save EdoardoVignati/5dbdbfa8c71792ae88d5dd04c1bd98ab to your computer and use it in GitHub Desktop.
Save EdoardoVignati/5dbdbfa8c71792ae88d5dd04c1bd98ab to your computer and use it in GitHub Desktop.
Git Wizard πŸ§™β€β™‚οΈ - Git bulk operations manager (Windows only)
:: Prerequisite: git
:: Usage: Download the wizard
:: Create a file named "repos.txt" in the same folder of the wizard
:: Insert in the file the absolute path of the repositories to track, one per line
:: Double click on the wizard and follow the instructions
:: Contribution: Feel free to contribute to this script!
:: Credits: Edoardo Vignati <edoardo.vignati@akkodis.com>
:: Emanuele De Filippis <emanuele.defilippis@akkodis.com>
:: Initial setup
@echo off
Setlocal EnableDelayedExpansion
:: Welcome
echo Welcome, this is your git wizard!
echo:
:: Check git status
echo Checking git...
for /F "delims=" %%i in ("where git \n") do set "gitpath=%%i" || :error
set gitpath="C:\Program Files\Git\cmd\git.exe"
echo %gitpath%
echo:
:: Starting dir
set "originaldir=%cd%"
:: Repositories list
REM echo Your repo list will be read from:
REM echo "%originaldir%\repos.txt"
echo:
set /p "repos_input=>> Enter name of file repo list: "
:loop
:: Operation selection
echo:
echo Type 'help' for more or 'exit' to terminate
echo:
set /p "opcode=>> Enter an option: "
echo:
:: Just exit
if %opcode%==exit exit
:: Help menu
if %opcode%==help (
echo ===================
echo Available options
echo ===================
echo status.............Show what's new locally
echo pull...............Pull everything from the repositories
echo push...............Push everything to remote repositories
echo update.............Check the status, pull differences and push what's new
echo help...............Print this helper
echo exit...............Close the terminal
echo:
echo ===================
echo Useful notes
echo ===================
echo To store git secret you can use the following command:
echo git config credential.helper store
)
:: Just pull
if %opcode%==pull (
for /f "tokens=*" %%f in (%repos_input%) do (
echo ====================================
echo %%f
echo ====================================
cd /D %%f
git pull --rebase || :error
cd /D %originaldir%
)
)
:: Just add, commit and push everything. Always.
if %opcode%==push (
for /f "tokens=*" %%f in (%repos_input%) do (
echo ====================================
echo %%f
echo ====================================
cd /D %%f
git add --all || :error
set /p "message=Enter commit message: "
git commit -m "%message%" || :error
git push || :error
cd /D %originaldir%
)
)
:: Status of repositories
if %opcode%==status (
for /f "tokens=*" %%f in (%repos_input%) do (
echo ====================================
echo %%f
echo ====================================
cd /D %%f
git status || :error
cd /D %originaldir%
)
)
:: Do a lot of things to update remote and local repos
if %opcode%==update (
for /f "tokens=*" %%f in (%repos_input%) do (
echo ====================================
echo %%f
echo ====================================
cd /D %%f
set "lastoutputrow=empty"
for /f "delims=" %%i in ('git status') do (
set "lastoutputrow=%%i"
)
if "!lastoutputrow!"=="nothing to commit, working tree clean" (
echo Nothing new here. Pulling and skipping...
git pull --rebase || :error
) else (
git add --all || :error
set /p "message=Enter commit message: "
git commit -m "!message!" || :error
git pull --rebase || :error
git push || :error
)
cd /D %originaldir%
)
)
goto loop
:error
echo Failed with error #%errorlevel%.
goto loop
:: Notes
:: ==========================
:: Put here something useful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment