git 如何从 Visual Studio 2013 向 GitHub 添加现有解决方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19982053/
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
How do I add an existing Solution to GitHub from Visual Studio 2013
提问by Richard210363
I have looked through many web pages on the new Git integration in VS 2013 and they do not deal with adding an existing solution to Github. In fact I can't find much on using GitHub instead of Visual Studio Online.
我浏览了许多关于 VS 2013 中新的 Git 集成的网页,他们没有处理向 Github 添加现有解决方案的问题。事实上,我找不到太多关于使用 GitHub 而不是 Visual Studio Online 的信息。
Can anyone tell me how I start from an existing solution and add it to Github using the tools in VS 2013.
谁能告诉我如何从现有解决方案开始并使用 VS 2013 中的工具将其添加到 Github。
回答by Richard210363
OK this worked for me.
好的,这对我有用。
- Open the solution in Visual Studio 2013
- Select File | Add to Source Control
- Select the Microsoft Git Provider
- 在 Visual Studio 2013 中打开解决方案
- 选择文件 | 添加到源代码管理
- 选择 Microsoft Git 提供程序
That creates a local GIT repository
这将创建一个本地 GIT 存储库
- Surf to GitHub
- Create a new repository DO NOT SELECT Initialize this repository with a README
- 浏览到 GitHub
- 创建一个新的存储库不要选择用 README 初始化这个存储库
That creates an empty repository with no Master branch
这将创建一个没有主分支的空存储库
- Once created open the repository and copy the URL (it's on the right of the screen in the current version)
- Go back to Visual Studio
- Make sure you have the Microsoft Git Provider selected under Tools/Options/Source Control/Plug-in Selection
- Open Team Explorer
- Select Home | Unsynced Commits
- Enter the GitHub URL into the yellow box (use HTTPS URL, not the default shown SSH one)
- Click Publish
- Select Home | Changes
- Add a Commit comment
- Select Commit and Push from the drop down
- 创建后打开存储库并复制 URL(它在当前版本的屏幕右侧)
- 返回到 Visual Studio
- 确保在工具/选项/源代码控制/插件选择下选择了 Microsoft Git 提供程序
- 打开团队资源管理器
- 选择首页 | 未同步提交
- 在黄色框中输入 GitHub URL(使用 HTTPS URL,而不是默认显示的 SSH 之一)
- 点击发布
- 选择首页 | 变化
- 添加提交评论
- 从下拉列表中选择提交和推送
Your solution is now in GitHub
您的解决方案现已在 GitHub 中
回答by MaKiPL
There is a lot easier way to do this that doesn't even require you to do anything outside Visual Studio.
有很多更简单的方法可以做到这一点,甚至不需要你在 Visual Studio 之外做任何事情。
- Open your project in Visual Studio
- File> Add to source control
- Open Team Explorer, click on Homebutton, proceed to "Sync" and there you'd find the "Publish to GitHub". Click on "Get Started"
- Type title of your repository and description (optionally).
- Click on "Publish"
- 在 Visual Studio 中打开您的项目
- 文件>添加到源代码管理
- 打开团队资源管理器,单击主页按钮,继续“同步”,您会在那里找到“发布到 GitHub”。点击“开始”
- 键入存储库的标题和描述(可选)。
- 点击“发布”
That's all. Visual Studio github plugin automatically created repository for you and configured everything. Now just click on Homeand choose "Changes" tab and finally commit your first commit.
就这样。Visual Studio github 插件会自动为您创建存储库并配置所有内容。现在只需单击主页并选择“更改”选项卡,最后提交您的第一次提交。
回答by jjjjs
This question has already been answered accurately by Richard210363.
这个问题已经被Richard210363准确回答了。
However, I would like to point out that there is another way to do this, and to warn that this alternate approach should be avoided, as it causes problems.
但是,我想指出还有另一种方法可以做到这一点,并警告应避免这种替代方法,因为它会导致问题。
As R0MANARMY stated in a comment to the original question, it is possible to create a repo from the existing solution folder using the git command line or even Git Gui. However, when you do this it adds allthe files below that folder to the repo, including build output (bin/ obj/ folders) user options files (.suo, .csproj.user) and numerous other files that may be in your solution folder but that you don't want to include in your repo. One unwanted side effect of this is that after building locally, the build output will show up in your "changes" list.
正如 R0MANARMY 在对原始问题的评论中所述,可以使用 git 命令行甚至 Git Gui 从现有解决方案文件夹创建存储库。但是,当您执行此操作时,它会将该文件夹下的所有文件添加到存储库中,包括构建输出(bin/obj/ 文件夹)用户选项文件(.suo、.csproj.user)以及您的解决方案中可能存在的许多其他文件文件夹,但您不想包含在您的存储库中。这样做的一个不良副作用是,在本地构建后,构建输出将显示在您的“更改”列表中。
When you add using "Select File | Add to Source Control" in Visual Studio, it intelligently includes the correct project and solution files, and leaves the other ones out. Also it automatically creates a .gitignore file that helps prevent these unwanted files from being added to the repo in the future.
在 Visual Studio 中使用“选择文件 | 添加到源代码管理”添加时,它会智能地包含正确的项目和解决方案文件,而将其他文件排除在外。它还会自动创建一个 .gitignore 文件,以帮助防止将来将这些不需要的文件添加到存储库中。
If you have already created a repo that includes these unwanted files and then add the .gitignore file at a later time, the unwanted files will still remain part of the repo and will need to be removed manually... it's probably easier to delete the repo and start over again by creating the repo the correct way.
如果您已经创建了一个包含这些不需要的文件的存储库,然后稍后添加 .gitignore 文件,则不需要的文件仍将保留在存储库中,需要手动删除……删除这些文件可能更容易回购并通过以正确的方式创建回购重新开始。
回答by jjjjs
- From the Team Explorer menu click "add" under the Git repository section (you'll need to add the solution directory to the Local Git Repository)
- Open the solution from Team Explorer (right click on the added solution - open)
- Click on the commit button and look for the link "push"
- 在 Team Explorer 菜单中,单击 Git 存储库部分下的“添加”(您需要将解决方案目录添加到本地 Git 存储库)
- 从 Team Explorer 打开解决方案(右键单击添加的解决方案 - 打开)
- 单击提交按钮并查找链接“推送”
Visual Studio should now ask your GitHub credentials and then proceed to upload your solution.
Visual Studio 现在应该询问您的 GitHub 凭据,然后继续上传您的解决方案。
Since I have my Windows account connected to Visual Studio to work with Team Foundation I don't know if it works without an account, Visual Studio will keep track of who commits so if you are not logged in it will probably ask you to first.
由于我的 Windows 帐户已连接到 Visual Studio 以与 Team Foundation 一起工作,我不知道它是否可以在没有帐户的情况下工作,Visual Studio 将跟踪谁提交,因此如果您未登录,它可能会首先要求您登录。
回答by Nish
Well, I understand this question is Visual Studio GUI related, but maybe the asker can try this trick also. Just giving a different perspective in solving this problem.
好吧,我知道这个问题与 Visual Studio GUI 相关,但也许提问者也可以尝试这个技巧。只是给出了解决这个问题的不同视角。
I like to use terminal a lot for GIT, so here are the simple steps:
我喜欢在 GIT 中经常使用终端,所以这里是简单的步骤:
Pre-requisites...
先决条件...
- If it's Linux or MAC, you should have git packages installed on your machine
- If it's Windows, you can try to download git bash software
- 如果是 Linux 或 MAC,你应该在你的机器上安装 git 包
- 如果是Windows,可以尝试下载git bash软件
Now,
现在,
- Goto Github.com
- In your account, create a New Repository
Don't create any file inside the repository. Keep it empty. Copy its URL. It should be something like https://github.com/Username/ProjectName.git
Open up the terminal and redirect to your Visual Studio Project directory
Configure your credentials
git config --global user.name "your_git_username" git config --global user.email "your_git_email"
Then type these commands
git init git add . git commit -m "First Migration Commit" git remote add origin paste_your_URL_here git push -u origin master
- 转到 Github.com
- 在您的帐户中,创建一个新的存储库
不要在存储库中创建任何文件。让它空着。复制其网址。它应该类似于 https://github.com/Username/ProjectName.git
打开终端并重定向到您的 Visual Studio 项目目录
配置您的凭据
git config --global user.name "your_git_username" git config --global user.email "your_git_email"
然后输入这些命令
git init git add . git commit -m "First Migration Commit" git remote add origin paste_your_URL_here git push -u origin master
Done...Hope this helps
完成...希望这有帮助
回答by Lee
None of the answers were specific to my problem, so here's how I did it.
没有一个答案是针对我的问题的,所以我是这样做的。
This is for Visual Studio 2015 and I had already made a repository on Github.com
这是针对 Visual Studio 2015 的,我已经在 Github.com 上创建了一个存储库
If you already have your repository URL copy it and then in visual studio:
如果您已经拥有存储库 URL,请复制它,然后在 Visual Studio 中:
- Go to Team Explorer
- Click the "Sync" button
- It should have 3 options listed with "get started" links.
- I chose the "get started" link against "publish to remote repository", which it the bottom one
- A yellow box will appear asking for the URL. Just paste the URL there and click publish.
- 转到团队资源管理器
- 单击“同步”按钮
- 它应该有 3 个选项,其中列出了“开始”链接。
- 我选择了针对“发布到远程存储库”的“入门”链接,它是最底层的
- 将出现一个黄色框,询问 URL。只需将 URL 粘贴到那里,然后单击发布。
回答by Laurie Stearn
It's a few less clicks in VS2017, and if the local repo is ahead of the Git clone, click Source control from the pop-up project menu:
This brings up the Team Explorer Changes dialog:
Type in a description- here it's "Stack Overflow Example Commit".
Make a choice of the three options on offer, all of which are explained here.
在 VS2017 中点击次数更少,如果本地存储库在 Git 克隆之前,请从弹出的项目菜单中单击源代码控制:
这将打开团队资源管理器更改对话框:
输入描述 - 这里是“堆栈溢出”示例提交”。在提供的三个选项中进行选择,所有这些选项都在此处进行了说明。
回答by Tarun
My problem is that when i use https for the remote URL, it doesn't work, so I use http instead. This allows me to publish/sync with GitHub from Team Explorer instantly.
我的问题是,当我使用 https 作为远程 URL 时,它不起作用,所以我使用 http。这使我可以立即从 Team Explorer 发布/与 GitHub 同步。