Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve Github repository name using GitPython

Is there a way to get the repository name using GitPython?

repo = git.Repo.clone_from(repoUrl, ".", branch=branch)

I can't seem to find any properties attached to the repo object which has this information. It might be that I misunderstand how github/GitPython works.

like image 599
erihanse Avatar asked Mar 13 '19 00:03

erihanse


1 Answers

Simple, compact, and robust that works with remote .git repos:

 from git import Repo

 repo = Repo(repo_path)

 # For remote repositories
 repo_name = repo.remotes.origin.url.split('.git')[0].split('/')[-1]

 # For local repositories
 repo_name = repo.working_tree_dir.split("/")[-1]
like image 77
nimig18 Avatar answered Sep 19 '22 13:09

nimig18