Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing GitPython module to get remote HEAD branch
    text
    copied!<p>I'm trying to use GitPython to write some Python scripts which I can use it to simplify my daily tasks as I manage many branches.</p> <p>I'm also quite new for Python when it comes to writing complicated scripts.</p> <p>This is the API I used: <a href="http://packages.python.org/GitPython/0.3.2/index.html">GitPython API doc</a></p> <p>I want to write it in GitPython that simply does the following and parse out the part which shows me the HEAD remote branch is pointing. In another word, I want to basically get the <code>remotes/origin/HEAD</code></p> <pre><code>$ git branch -a master * branch_to_remove remotes/origin/HEAD -&gt; origin/master remotes/origin/master remotes/origin/testing </code></pre> <p>I browse the API doc many times, at first I'm having trouble to understand the Python format of these API docs, and I couldn't find anything useful to use to do for this other than <code>remote_head</code> in <code>class git.refs.reference.Reference(repo, path, check_path=True)</code> </p> <p>But I don't even know how to call/initialize it.</p> <p>Here is what I had so far, and you can tell what I'm trying to do, to simply reset to 'no branch' state and remove the current branch I'm on:</p> <pre><code>import git from git import * repo = git.Repo("/some/path/testing") repo.git.branch() [some code to get the remotes/origin/HEAD, set it to remoteHeadBranch ] repo.git.checkout(remoteHeadBranch) # this should reset the Git back to 'no branch' state repo.git.checkout(D="branch_to_remove") </code></pre> <p>Any help is much appreciated!</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload