Skip to content

Instantly share code, notes, and snippets.

@attakei
Created December 30, 2017 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attakei/213bb6089a26cf647d0f9080571a14fb to your computer and use it in GitHub Desktop.
Save attakei/213bb6089a26cf647d0f9080571a14fb to your computer and use it in GitHub Desktop.
Checkout all branches from 'origin'
#!/usr/bin/env python
"""Generated by act as 2017-12-30 09:57:20.386358
"""
import sys
import logging
from pathlib import Path
from git import Repo
Logger = logging.getLogger('checkout_all_branches')
def main(argv=None):
Logger.debug('Start')
if argv is None:
argv = sys.argv[1:]
if len(argv) != 1:
Logger.error('Path required')
return 1
target = Path(argv[0]).absolute()
for path in target.glob('*'):
print(path)
if not path.joinpath('.git').exists():
Logger.info('Not git, skip')
continue
repo = Repo(str(path))
origin = repo.remotes.origin
for remote in origin.refs:
if str(remote) == 'origin/HEAD':
continue
local = '/'.join(str(remote).split('/')[1:])
repo.create_head(local, remote)
break
Logger.debug('End')
return 0
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment