git 如何将 Visual Studio 2015 连接到现有的 Gitlab 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35167121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:54:38  来源:igfitidea点击:

How to connect Visual Studio 2015 to an existing Gitlab project?

gitvisual-studiovisual-studio-2015gitlab

提问by Andrew Savinykh

There is an on-premise instance of gitlabinstalled. There are Visual Studio projects in this instance. What is the easiest way of connecting Visual Studio 2015 to one of the projects?

安装了一个内部部署的gitlab实例。此实例中有 Visual Studio 项目。将 Visual Studio 2015 连接到其中一个项目的最简单方法是什么?

With GitHub, you can do it by selecting "Connect to GitHub" as on the following picture: enter image description here

使用 GitHub,您可以通过选择“连接到 GitHub”来完成,如下图所示: 在此处输入图片说明

and then pasting the repository url. There is no GitLab option in the drop down. What is the easiest way of configuring Visual Studio 2015 to work with a solution from gitlab repository? By work I mean to have your usual source control bindings to the repository.

然后粘贴存储库网址。下拉菜单中没有 GitLab 选项。配置 Visual Studio 2015 以使用来自 gitlab 存储库的解决方案的最简单方法是什么?通过工作,我的意思是将您通常的源代码控制绑定到存储库。

Note, that this question is probably useful in more general context of connecting to anygit repository that is not GitHub, and does not have direct support with built-in Visual Studio menu, not just to GitLab repository.

请注意,这个问题在连接到任何GitHub 以外的 git 存储库的更一般的上下文中可能很有用,并且不直接支持内置的 Visual Studio 菜单,而不仅仅是连接到 GitLab 存储库。

采纳答案by Andrew Savinykh

First, get the clone using command line:

首先,使用命令行获取克隆:

git clone <repository url>

Then in Visual Studio, in the Team Explorer pane, select the connect button and look for Local Git Repositories "tab":

然后在 Visual Studio 的团队资源管理器窗格中,选择连接按钮并查找本地 Git 存储库“选项卡”:

enter image description here

在此处输入图片说明

Press Add, as indicated on the picture, and select the folder you cloned your repository too.

按添加,如图所示,并选择您克隆存储库的文件夹。

When the process finishes, you can double-click the added repo to "connect" to it, and then select and open a solution it contains. After that follow your usual Visual Studio git workflow.

该过程完成后,您可以双击添加的存储库以“连接”到它,然后选择并打开它包含的解决方案。之后,按照您通常的 Visual Studio git 工作流程进行操作。

回答by Saineshwar

Now its simple to Use GitLab with Visual studio 2015 just add GitLab Extensions to Visual studio and you are there.

现在,在 Visual Studio 2015 中使用 GitLab 很简单,只需将 GitLab 扩展添加到 Visual Studio 即可。

  1. Steps for Adding GitLab Extensions to Visual studio
  1. 将 GitLab 扩展添加到 Visual Studio 的步骤

enter image description here

在此处输入图片说明

  1. In Search of Extensions and updates choose online and search GitLab.
  1. 在搜索扩展和更新中选择在线并搜索 GitLab。

enter image description here

在此处输入图片说明

回答by Peyman Mahdavi

For using gitlab when you have ssh keys and also your ssh key have passphrase, you have to follow instructions as follow (don't forget to upload your public key to gitlab)(also you must use a private key which its format is openssh):

当您有 ssh 密钥并且您的 ssh 密钥有密码短语时,要使用 gitlab,您必须按照以下说明操作(不要忘记将您的公钥上传到 gitlab)(您还必须使用其格式为 openssh 的私钥) :

  1. Have your project folder and its files.
  2. Have Git Bash installed on your system.
  3. Using git bash, go to your project directory.
  4. git config --global user.name "your-name"
  5. git config --global user.email "your-email-address"
  6. git init
  7. ssh-agent bash -c 'ssh-add “private-key-local-address”; git remote add origin “online-repo-address”'(will be asked for passphrase)
  8. git add .
  9. git commit -m “initial commit”
  10. ssh-agent bash -c 'ssh-add “private-key-local-address”; git push -u origin master'(will be asked for passphrase)
  11. in visual studio, right-click on the solution, select add solution to source control. (visual studio will automatically find repository)
  1. 拥有您的项目文件夹及其文件。
  2. 在您的系统上安装 Git Bash。
  3. 使用 git bash,转到您的项目目录。
  4. git config --global user.name "your-name"
  5. git config --global user.email "your-email-address"
  6. git init
  7. ssh-agent bash -c 'ssh-add “private-key-local-address”; git remote add origin “online-repo-address”'(将被要求输入密码)
  8. git add .
  9. git commit -m “initial commit”
  10. ssh-agent bash -c 'ssh-add “private-key-local-address”; git push -u origin master'(将被要求输入密码)
  11. 在visual studio中,右键单击解决方案,选择将解决方案添加到源代码管理。(visual studio 会自动找到repository)

For further commits, you can commit changes in visual studio (ONLY COMMIT) and then repeat step 10 to push them to gitlab servers.

对于进一步的提交,您可以在 Visual Studio 中提交更改(仅提交),然后重复步骤 10 将它们推送到 gitlab 服务器。

edit: for send a project from visual studio to gitlab use git remote add originand for get project from gitlab to visual studio use git cloneinstead!

编辑:将项目从 Visual Studio 发送到 gitlab 使用,git remote add origin并将项目从 gitlab 发送到 Visual Studio 使用git clone