[英]HOW TO - Connect to DevOps Uninitialized Git Repository (git remote add origin to uninitialized repo)
I am creating a Project with git on DevOps using API. By default DevOps creates a git repository with same same name as project.我正在使用 API 在 DevOps 上创建一个带有 git 的项目。默认情况下,DevOps 创建一个与项目同名的 git 存储库。 I already have a project on my local machine and want to connect to that git repo and push it there.
我的本地机器上已经有一个项目,想连接到 git 存储库并将其推送到那里。
How can I do that?我怎样才能做到这一点? Please help.
请帮忙。
PS : I have to do it programmatically with C# code. PS:我必须使用 C# 代码以编程方式进行。
Thanks in Advance.提前致谢。
You have to add the proper git remote
, found on the initial project repo page.您必须添加正确的
git remote
,在初始项目 repo 页面上找到。
After creating a new project, the repo page looks like this:创建新项目后,repo 页面如下所示:
The second block contains the code for getting adding existing repo from command line.第二个块包含用于从命令行添加现有存储库的代码。 Let's say I have this local folder at
C:\work\githubtest
and just follow the commands above.假设我在
C:\work\githubtest
有这个本地文件夹,只需按照上面的命令操作即可。 For the example I'm showing above the red rectangle:对于我在红色矩形上方显示的示例:
The suggested commands from the rectangle and the screenshot are:矩形和屏幕截图中的建议命令是:
git remote add origin https://yourorg@dev.azure.com/yourorg/GithubTest/_git/GithubTest
git push -u origin --all
So, your question is how to do this programmatically, in C# ?那么,您的问题是如何在 C# 中以编程方式执行此操作? Well the part of the git command is asked and answered here This could look in your example something like:
那么 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.