Guest User

Untitled

a guest
Nov 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. from git import Git
  2. g = Git()
  3.  
  4. g.checkout("mybranch")
  5.  
  6. g.branch()
  7.  
  8. from git import Repo
  9. r = Repo(your_repo_path)
  10. repo_heads = r.heads # or it's alias: r.branches
  11.  
  12. repo_heads_names = [h.name for h in repo_heads]
  13.  
  14. repo_heads['master'].checkout()
  15. # you can get elements of IterableList through it_list['branch_name']
  16. # or it_list.branch_name
  17.  
  18. import git
  19.  
  20. repo = git.Repo(repo_path)
  21. branches = []
  22. for r in repo.branches:
  23. branches.append(r)
  24. # check if a tracking branch exists
  25. tb = t.tracking_branch()
  26. if tb:
  27. branches.append(tb)
  28.  
  29. def get_all_branches(path):
  30. cmd = ['git', '-C', path, 'branch', '-a']
  31. out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
  32. return out
  33.  
  34. import os, git
  35.  
  36. # Create repo for current directory
  37. repo = git.Repo(os.getcwd())
  38.  
  39. # Run "git branch -r" and collect results into array
  40. remote_branches = []
  41. for ref in repo.git.branch('-r').split('n'):
  42. print ref
  43. remote_branches.append(ref)
Add Comment
Please, Sign In to add comment