如何配置 Visual Studio 2013 以与 Git/SourceTree 一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25941306/
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-19 10:24:44  来源:igfitidea点击:

How do I configure Visual Studio 2013 for use with Git/SourceTree

gitvisual-studio-2013atlassian-sourcetree

提问by serlingpa

I would like to be able to use Git with Visual Studio 2013. I would also like to be able to use SourceTree but I don't know how the two play together.

我希望能够在 Visual Studio 2013 中使用 Git。我也希望能够使用 SourceTree,但我不知道两者如何一起使用。

I have created a project in Visual Studio, configuring it to use Git, but I have no idea where the repository has been created or how I can push it out to a remote repository (BitBucket). Can anyone explain how these three technologies can be made to work with each other?

我在 Visual Studio 中创建了一个项目,将其配置为使用 Git,但我不知道存储库是在哪里创建的,也不知道如何将其推送到远程存储库 (BitBucket)。谁能解释一下这三种技术如何相互配合?

I have looked at the Atlassian Connector for Visual Studio but I have had no luck with it.

我已经查看了用于 Visual Studio 的 Atlassian 连接器,但我没有运气。

Thanks in advance.

提前致谢。

M

回答by jasonpresley

I blogged about this on my site. Below are the directions that I give to students to get these three technologies (BitBucket, SourceTree and Visual Studio) to work together. Please remember some of the instructions here are very specific about things like the path to set simply because when I have 12 people all doing the same thing I need to make sure that everyone does it the same. Change these things to fit your need. You can view this post on my blog to download a PDF file of these instructions which also contains pictures. http://webdevbeyondtheclassroom.wordpress.com/2014/10/22/using-source-control-with-bitbucket-source-tree-and-visual-studio-part-1/

我在我的网站上写了关于这个的博客。下面是我给学生的指导,让这三种技术(BitBucket、SourceTree 和 Visual Studio)协同工作。请记住这里的一些说明非常具体,比如设置路径,因为当我有 12 个人都做同样的事情时,我需要确保每个人都做同样的事情。更改这些内容以满足您的需要。您可以在我的博客上查看这篇文章以下载这些说明的 PDF 文件,其中还包含图片。http://webdevbeyondtheclassroom.wordpress.com/2014/10/22/using-source-control-with-bitbucket-source-tree-and-visual-studio-part-1/

Account Setup

帐户设置

Install Git

安装 Git

  • In a web browser open up www.git-scm.com
  • Click the “Downloads for Windows” button
  • After downloading, install Git using all of the preselected defaults
  • 在网络浏览器中打开 www.git-scm.com
  • 单击“Windows 下载”按钮
  • 下载后,使用所有预选的默认值安装 Git

Installing Source Tree

安装源码树

  • In a web browser open up www.sourcetreeapp.com
  • Click the “Download SourceTree Free” button
  • After downloading, install SourceTree using all of the preselected defaults
  • 在网络浏览器中打开 www.sourcetreeapp.com
  • 单击“免费下载 SourceTree”按钮
  • 下载后,使用所有预选的默认值安装 SourceTree

Create Bit Bucket Account

创建比特桶账户

  • In a web browser open up www.bitbucket.org
  • Enter your information into the sign up form on the front page and click “Sign up for free”
  • Enter all your information and follow all sign up instructions
  • At the “Create Your First Repository” screen click No Thanks
  • 在网络浏览器中打开 www.bitbucket.org
  • 在首页的注册表单中输入您的信息,然后单击“免费注册”
  • 输入您的所有信息并按照所有注册说明进行操作
  • 在“创建您的第一个存储库”屏幕上单击不,谢谢

Repository Creation

存储库创建

Creating a Repository on BitBucket and Cloning in SourceTree

在 BitBucket 上创建存储库并在 SourceTree 中进行克隆

  • Open and sign in to www.bitbucket.org if you are not already there
  • At the top click on the “Repository” menu option and select “Create repository”
  • Enter a new name for your repository (This will be your solution name in Visual Studio)
  • Enter a description if desired
  • Leave the Access Level checked to make this a private repository
  • Leave Repository Type set to Git
  • Click the “Create respository” button
  • On the next screen click the Clone link on the left hand menu
  • Click the Clone in SourceTree button
  • The SourceTree application will open with a URL Actions dialog box
  • IMPORTANT: Click the ellipse button […] to the right of the Destination Path input box
  • In the “Select Destination Path” dialog box navigate to the following location
  • C:\Users[username]\Documents\Visual Studio 2012\Projects
  • Create a new folder in this dialog box naming it the same as your repository name
  • Double click the new folder and click the Select Folder button
  • Back on the URL Actions dialog box click the Clone button
  • 如果您尚未登录 www.bitbucket.org,请打开并登录
  • 在顶部单击“存储库”菜单选项并选择“创建存储库”
  • 为您的存储库输入一个新名称(这将是您在 Visual Studio 中的解决方案名称)
  • 如果需要,输入描述
  • 选中访问级别以使其成为私有存储库
  • 将存储库类型设置为 Git
  • 单击“创建存储库”按钮
  • 在下一个屏幕上单击左侧菜单上的克隆链接
  • 单击 SourceTree 中的克隆按钮
  • SourceTree 应用程序将打开一个 URL 操作对话框
  • 重要提示:单击“目标路径”输入框右侧的椭圆按钮 [...]
  • 在“选择目标路径”对话框中导航到以下位置
  • C:\用户[用户名]\Documents\Visual Studio 2012\Projects
  • 在此对话框中创建一个新文件夹,将其命名为与您的存储库名称相同的名称
  • 双击新文件夹,然后单击“选择文件夹”按钮
  • 返回 URL 操作对话框,单击克隆按钮

Creating a New Solution in Visual Studio

在 Visual Studio 中创建新解决方案

  • Open Visual Studio
  • Create a New Project from the start screen or File > New > Project
  • Select the Project type that you are going to create
  • In the Name box change the default name to the name of the repository you created in bitbucket
  • Click the Browse button to the right of the Location box
  • Navigate to and double click on the folder you created when you cloned the repository
  • C:\Users[username]\Documents\Visual Studio 2012\Projects[repositoryname]\
  • Leave the checkbox for “Create directory for solution” checked
  • Click the OK button.
  • 打开 Visual Studio
  • 从开始屏幕或文件 > 新建 > 项目创建一个新项目
  • 选择您要创建的项目类型
  • 在名称框中将默认名称更改为您在 bitbucket 中创建的存储库的名称
  • 单击“位置”框右侧的“浏览”按钮
  • 导航到克隆存储库时创建的文件夹并双击
  • C:\Users[用户名]\Documents\Visual Studio 2012\Projects[存储库名称]\
  • 选中“为解决方案创建目录”复选框
  • 单击确定按钮。

Initial Project Commit and Push to BitBucket

初始项目提交并推送到 BitBucket

Commiting Changes in SourceTree

在 SourceTree 中提交更改

  • In SourceTree double click on your newly created project on the left
  • Check the box next to Unstaged files
  • All the files should transfer to the above pane as Staged files
  • Click the Commit button on the top bar
  • In the text area that will eventually appear at the bottom of SourceTree enter the commit message of “Initial Commit”
  • Click the commit button
  • 在 SourceTree 中双击左侧新创建的项目
  • 选中未暂存文件旁边的框
  • 所有文件都应作为暂存文件传输到上面的窗格
  • 单击顶部栏上的提交按钮
  • 在最终出现在 SourceTree 底部的文本区域输入“Initial Commit”的提交信息
  • 点击提交按钮

Pushing Changes to BitBucket

将更改推送到 BitBucket

  • In SourceTree click the Push button on the top menu
  • On the new dialog box click the master check box
  • Click OK
  • Click the “Show Full Output” check box to see the Completed successfully message (this will also show you any error messages. NOTE: If you don't when the push is complete, if successful, the box simply goes away.
  • When completed click the close button
  • 在 SourceTree 中单击顶部菜单上的 Push 按钮
  • 在新对话框中单击主复选框
  • 单击确定
  • 单击“显示完整输出”复选框以查看“已成功完成”消息(这也会向您显示任何错误消息。注意:如果在推送完成时不这样做,如果成功,该框就会消失。
  • 完成后点击关闭按钮