Created
February 22, 2023 00:25
-
-
Save igorcosta/bcdfcf45c86672d141b64ebb7fc6a537 to your computer and use it in GitHub Desktop.
A handy script to shift GitHub repos from one place to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Make sure you change this script chmod to executable | |
# Set your GitHub username and access token | |
USERNAME={REPLACE_ME} | |
ACCESS_TOKEN={REPLACE_ME} | |
# Set the path to the directory where you want to store your repositories | |
LOCAL_REPO_DIR=/path/to/your/local/repo/directory | |
# Set the URL of the new server where you want to push the code | |
[email protected]:newrepo.git | |
# Iterate through each repository in your GitHub account | |
for REPO_NAME in $(curl -s -u ${USERNAME}:${ACCESS_TOKEN} https://api.github.com/user/repos\?per_page\=1000 | grep -o '"clone_url":"[^"]*' | sed 's/"clone_url":"//'); | |
do | |
REPO_DIR=${LOCAL_REPO_DIR}/${REPO_NAME##*/} | |
# Clone the repository to your local machine | |
git clone $REPO_NAME $REPO_DIR | |
# Print a message indicating that the repository has been cloned | |
echo "Cloned ${REPO_NAME##*/} to $REPO_DIR" | |
# Change the remote origin to the new server URL | |
cd $REPO_DIR | |
git remote set-url origin $NEW_SERVER_URL | |
# Push the code to the new server | |
git push --all | |
git push --tags | |
# Print a message indicating that the code has been pushed to the new server | |
echo "Pushed code to $NEW_SERVER_URL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About this script
Things to consider: