How to push (with libgit2)

瘦欲@ 提交于 2019-12-05 06:09:05

The code that does the trick is:

 bool push(git_repository *repository) 
 {
     // get the remote.
     git_remote* remote = NULL;
     git_remote_lookup( &remote, repository, "origin" );

     // connect to remote
     git_remote_connect( remote, GIT_DIRECTION_PUSH )

     // add a push refspec
     git_remote_add_push( remote, "refs/heads/master:refs/heads/master" );

     // configure options
     git_push_options options;
     git_push_init_options( &options, GIT_PUSH_OPTIONS_VERSION );

     // do the push
     git_remote_upload( remote, NULL, &options );

     git_remote_free( remote );
     return true; 
 }

Of course, you should do some error checks which I omitted for conciseness.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!