[英]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.