Skip to content

Instantly share code, notes, and snippets.

@pnappa
Last active August 15, 2018 04:34
Show Gist options
  • Save pnappa/fa0b1d0ab42eae55666ace976f0ed5fb to your computer and use it in GitHub Desktop.
Save pnappa/fa0b1d0ab42eae55666ace976f0ed5fb to your computer and use it in GitHub Desktop.
Python script to clone git repos into a structured format
#!/usr/bin/python3
"""
This script will clone your repositories to a consistent directory hierarchy.
e.g the following will install the repo to ~/github.com/pnappa/xkcdfools
$ gitclono.py git@github.com:pnappa/xkcdfools.git
This is a nice way to organise your repositories, symlinking to them when necessary.
"""
import os
import sys
import subprocess
if len(sys.argv) != 2:
print("incorrect number of arguments, usage:\n", sys.argv[0], "git@DOMAIN:user/repo.git")
sys.exit(-1)
s = sys.argv[1]
print(s)
directory = s
directory = directory[directory.find("@")+1:]
directory = directory[:directory.find(".git")]
directory = directory.replace(":", "/")
directory = os.path.join("/home", os.environ["USER"], directory)
print("cloning to", directory)
subprocess.call(["git", "clone", s, directory])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment