Skip to content

Instantly share code, notes, and snippets.

@luisehk
Created September 8, 2017 16:45
Show Gist options
  • Save luisehk/01b01f4ef0405047f51527e170c4ae22 to your computer and use it in GitHub Desktop.
Save luisehk/01b01f4ef0405047f51527e170c4ae22 to your computer and use it in GitHub Desktop.
Change git remotes
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))
@luisehk
Copy link
Author

luisehk commented Sep 8, 2017

After migrating your repos, run this script once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment