Created
September 8, 2017 16:45
-
-
Save luisehk/01b01f4ef0405047f51527e170c4ae22 to your computer and use it in GitHub Desktop.
Change git remotes
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
import subprocess | |
import os | |
def call(cmd): | |
print('Executing', cmd) | |
subprocess.call(cmd, shell=True) | |
def cd(d): | |
print('Changing dir', d) | |
os.chdir(os.path.join(os.getcwd(), d)) | |
with open('repos.txt') as f: | |
""" | |
Be careful, this script cannot be run twice because | |
it would remove your gitlab remote too | |
""" | |
# every line is a repo name | |
content = f.readlines() | |
content = [x.strip() for x in content] | |
# save initial working dir | |
cwd = os.getcwd() | |
for repo in content: | |
# always start from initial working dir | |
os.chdir(cwd) | |
# get into the repo folder | |
cd(repo) | |
# remove github remote | |
call('git remote remove origin'.format(repo)) | |
# rename gitlab remote | |
call('git remote rename gitlab origin'.format(repo)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After migrating your repos, run this script once