Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from git import Git
- g = Git()
- g.checkout("mybranch")
- g.branch()
- from git import Repo
- r = Repo(your_repo_path)
- repo_heads = r.heads # or it's alias: r.branches
- repo_heads_names = [h.name for h in repo_heads]
- repo_heads['master'].checkout()
- # you can get elements of IterableList through it_list['branch_name']
- # or it_list.branch_name
- import git
- repo = git.Repo(repo_path)
- branches = []
- for r in repo.branches:
- branches.append(r)
- # check if a tracking branch exists
- tb = t.tracking_branch()
- if tb:
- branches.append(tb)
- def get_all_branches(path):
- cmd = ['git', '-C', path, 'branch', '-a']
- out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
- return out
- import os, git
- # Create repo for current directory
- repo = git.Repo(os.getcwd())
- # Run "git branch -r" and collect results into array
- remote_branches = []
- for ref in repo.git.branch('-r').split('n'):
- print ref
- remote_branches.append(ref)
Add Comment
Please, Sign In to add comment