Skip to content

Instantly share code, notes, and snippets.

@frostbitten
Last active December 30, 2024 18:25
Show Gist options
  • Save frostbitten/e14d0234e129c4a869a5e1e5152c9ace to your computer and use it in GitHub Desktop.
Save frostbitten/e14d0234e129c4a869a5e1e5152c9ace to your computer and use it in GitHub Desktop.
local git clone with config duplication, on windows - so your remote urls and rest of config doesn't change when making a local copy (for multiple branches in active dev)
@echo off
setlocal
REM Check for minimum required arguments
if "%~1"=="" (
echo Usage: %0 source_project destination_project destination_branch [source_branch]
exit /b 1
)
REM Assign arguments to variables
set "SRC_PROJECT=%~1"
set "DEST_PROJECT=%~2"
set "DEST_BRANCH=%~3"
set "SOURCE_BRANCH=%~4"
REM Clone the source project to the destination
echo Cloning "%SRC_PROJECT%" to "%DEST_PROJECT%"...
git clone "%SRC_PROJECT%" "%DEST_PROJECT%"
if errorlevel 1 (
echo Failed to clone repository from "%SRC_PROJECT%" to "%DEST_PROJECT%".
exit /b 1
)
REM Copy the .git/config file from source to destination to ensure parity
echo Copying .git/config from "%SRC_PROJECT%" to "%DEST_PROJECT%"...
copy "%SRC_PROJECT%\.git\config" "%DEST_PROJECT%\.git\config" /y >nul
if errorlevel 1 (
echo Failed to copy .git/config file from "%SRC_PROJECT%".
exit /b 1
)
REM Navigate to the destination directory
cd "%DEST_PROJECT%"
REM If a source branch is specified, checkout the source branch
if not "%SOURCE_BRANCH%"=="" (
echo Checking out source branch "%SOURCE_BRANCH%"...
git checkout "%SOURCE_BRANCH%"
if errorlevel 1 (
echo Failed to checkout source branch "%SOURCE_BRANCH%".
exit /b 1
)
)
REM Create and switch to the destination branch
echo Creating and switching to branch "%DEST_BRANCH%"...
git checkout -b "%DEST_BRANCH%"
if errorlevel 1 (
echo Failed to create and switch to branch "%DEST_BRANCH%".
exit /b 1
)
REM Verify remote configuration
echo Verifying remote configuration...
git remote -v
endlocal
echo Done!
exit /b 0
coded by chat gpt 4o, directed by Matt Seremet aka frostbitten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment