簡體   English   中英

如何 - 連接到 DevOps 未初始化的 Git 存儲庫(git remote add origin to uninitialized repo)

[英]HOW TO - Connect to DevOps Uninitialized Git Repository (git remote add origin to uninitialized repo)

我正在使用 API 在 DevOps 上創建一個帶有 git 的項目。默認情況下,DevOps 創建一個與項目同名的 git 存儲庫。 我的本地機器上已經有一個項目,想連接到 git 存儲庫並將其推送到那里。

我怎樣才能做到這一點? 請幫忙。

PS:我必須使用 C# 代碼以編程方式進行。

提前致謝。

簡答

您必須添加正確的git remote ,在初始項目 repo 頁面上找到。

更長的答案

創建新項目后,repo 頁面如下所示: azdo 的新項目

第二個塊包含用於從命令行添加現有存儲庫的代碼。 假設我在C:\work\githubtest有這個本地文件夾,只需按照上面的命令操作即可。 對於我在紅色矩形上方顯示的示例:

  • 文件夾里有什么; README-local.MD
  • 我所承諾的; 上面的文件

添加本地回購

矩形和屏幕截圖中的建議命令是:

git remote add origin https://yourorg@dev.azure.com/yourorg/GithubTest/_git/GithubTest
git push -u origin --all

結果

AzDo 中的結果

C#

那么,您的問題是如何在 C# 中以編程方式執行此操作? 那么 git 命令的一部分在這里被詢問和回答這可能看起來像你的例子:

string directory = ""; // directory of the git repository

using (PowerShell powershell = PowerShell.Create()) {
    // this changes from the user folder that PowerShell starts up with to your git repository
    powershell.AddScript($"cd {directory}");

    powershell.AddScript(@"git remote add origin https://yourorg@dev.azure.com/yourorg/GithubTest/_git/GithubTest");
    powershell.AddScript(@"git push -u origin --all");

    Collection<PSObject> results = powershell.Invoke();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM