简体   繁体   中英

Git pull and Git clone using REST API

I want to execute git pull and git clone command via REST API. I have searched the api doc but not able to found anything useful. https://developer.github.com/v3/

You can download the repo as zip or tar from archive url.

Eg : https://api.github.com/repos/:owner/:repo/:archive_format/:ref

Archive_format can be zipball or tarball. Ref is the branch name, by default api will take master branch.

Then from this url, you can download the repo

URL url = new URL(urlStr);
try( ReadableByteChannel rbc = Channels.newChannel(url.openStream()) )
{
    try( FileOutputStream fos = new FileOutputStream(filepathToSave) )
    {
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    }
}

If you want to get a git repository and then be able to do git add , git commit or any other git command, use git clone .

If you just want to get the repository content, you can download an archive with the link https://github.com/ {OWNER}/{REPOSITORY}/archive/{BRANCH_NAME}.(zip|tar.gz), (eg https://github.com/ansible/ansible/archive/devel.tar.gz ).
But you won't be able to do any git interaction then...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM