Skip to content

Instantly share code, notes, and snippets.

@edihasaj
Created January 28, 2023 10:46
Show Gist options
  • Save edihasaj/778396cd084b91e47b290bd73742e85f to your computer and use it in GitHub Desktop.
Save edihasaj/778396cd084b91e47b290bd73742e85f to your computer and use it in GitHub Desktop.
Pull/Push different origin
# Set the new remote repository URL
$oldUrl = "https://github.com/your-git.git"
$newUrl = "https://target-git.git"
# Get the current directory
$currentDir = "C:\Users\where"
# Change directory to the .git folder
cd "$currentDir\.git"
# Replace the URL in the config file
(Get-Content config) | Foreach-Object { $_ -replace $oldUrl, $newUrl } | Set-Content config
# Change back to the original directory
cd $currentDir
# Perform a git pull
git pull
# Change directory to the .git folder
cd "$currentDir\.git"
# Replace the URL in the config file
(Get-Content config) | Foreach-Object { $_ -replace $newUrl, $oldUrl } | Set-Content config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment