[英]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 頁面上找到。
第二個塊包含用於從命令行添加現有存儲庫的代碼。 假設我在C:\work\githubtest
有這個本地文件夾,只需按照上面的命令操作即可。 對於我在紅色矩形上方顯示的示例:
矩形和屏幕截圖中的建議命令是:
git remote add origin https://yourorg@dev.azure.com/yourorg/GithubTest/_git/GithubTest
git push -u origin --all
那么,您的問題是如何在 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.