ObjectiveGit(二)push & pull

push

生成一個commit之后,接下來就可以推送到遠(yuǎn)端了。push之前需要獲取到遠(yuǎn)端倉庫信息。由于一個本地倉庫可以設(shè)置多個遠(yuǎn)端倉庫,這里默認(rèn)就取第一個遠(yuǎn)端倉庫。

GTConfiguration *conf = [_repo configurationWithError:NULL];
NSError *error = nil;
GTRemote *remote = [conf.remotes firstObject];

由于push操作是需要權(quán)限的,所以要配置用戶名和密碼。注意這里的key值和clone的時候不一樣。

GTCredentialProvider *provider = [GTCredentialProvider providerWithBlock:^GTCredential * _Nullable(GTCredentialType type, NSString * _Nonnull URL, NSString * _Nonnull userName) {
   GTCredential *cre = [GTCredential credentialWithUserName:@"xporter" password:@"12345678" error:NULL];
   return cre;
}];

 NSDictionary *remoteOptions = @{GTRepositoryRemoteOptionsCredentialProvider:provider};

獲取分支信息

GTBranch *curretntBarch = [_repo currentBranchWithError:&error];

開始向遠(yuǎn)端推送

BOOL r = [_repo pushBranch:curretntBarch toRemote:remote withOptions:pushOptions error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL * _Nonnull stop) {
    NSLog(@"%d/%d",current,total);
}];

如果沒有報錯的話就是推送成功了,可以到遠(yuǎn)端倉庫進(jìn)行驗證。

pull

要同步遠(yuǎn)端的指定分支的信息,就需要用到pull方法。先獲取需要更新的分支

GTBranch *brach = [_repo currentBranchWithError:NULL];

pull 也是需要權(quán)限信息的,要設(shè)置用戶信息

GTCredentialProvider *provider = [GTCredentialProvider providerWithBlock:^GTCredential * _Nullable(GTCredentialType type, NSString * _Nonnull URL, NSString * _Nonnull userName) {
   GTCredential *cre = [GTCredential credentialWithUserName:@"xporter" password:@"12345678" error:NULL];
   return cre;
}];

NSDictionary *remoteOptions = @{GTRepositoryRemoteOptionsCredentialProvider:provider};

獲取遠(yuǎn)端分支信息

GTConfiguration *conf = [_repo configurationWithError:NULL];
NSError *error = nil;
GTRemote *remote = [conf.remotes firstObject];

拉取遠(yuǎn)端信息

BOOL r = [_repo pullBranch:brach fromRemote:remote withOptions:pullOptions error:&error progress:^(const git_transfer_progress * _Nonnull progress, BOOL * _Nonnull stop) {

}];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Git 基礎(chǔ) 基本原理 客戶端并不是只提取最新版本的文件快照,而是把代碼倉庫完整的鏡像下來。這樣一來,任何一處協(xié)同...
    __silhouette閱讀 16,197評論 5 147
  • Git 命令行學(xué)習(xí)筆記 Git 基礎(chǔ) 基本原理 客戶端并不是只提取最新版本的文件快照,而是把代碼倉庫完整的鏡像下來...
    sunnyghx閱讀 4,152評論 0 11
  • 高老太太有個從不示人的大紅朱漆描龍雕鳳的盒子,一把古舊的銅鎖一直守著這個屬于老太太一個人的秘密。 高老太太年紀(jì)很老...
    淡淡青蓮閱讀 983評論 14 22
  • 我發(fā)布送書的文章后,大家反響熱烈,評論積極,并預(yù)祝我在廣州生活愉快。 感謝大家的言布施。 我希望大家可以輕松看書,...
    阿濤有點帥閱讀 367評論 3 2
  • 近日來江歌劉鑫案再次掀起波瀾,事件的男主角陳世峰同志再次提出了新理論:是江歌先用刀刺向他,自己不過是自衛(wèi)反...
    第六天魔閱讀 326評論 0 0

友情鏈接更多精彩內(nèi)容