VS Code - 连接到远程GIT存储库和PUSH本地文件到新的远程存储库

Dar*_*oN1 28 git visual-studio-code

我用Visual Studio Code 创建了一个本地项目,该项目实现了一个本地GIT存储库.

然后我在Visual Studio Online上创建了一个GIT存储库,我希望将所有项目文件推送到远程存储库...

这样做的正确程序是什么?

我这时的.git\config文件看起来像这样:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
Run Code Online (Sandbox Code Playgroud)

感谢支持

Chr*_*oph 63

我假设你开始在一个目录中工作,并没有在那里使用git.以下应该与git bash一起使用:

cd "path to your repo"
git init
git add . # if you want to commit everything. Otherwise use .gitconfig files
git commit -m "initial commit" # If you change anything, you can add and commit again...
Run Code Online (Sandbox Code Playgroud)

要添加遥控器,只需这样做

git remote add origin https://...
git remote show origin # if everything is ok, you will see your remote
git push -u origin master # assuming your are on the master branch.
Run Code Online (Sandbox Code Playgroud)

所述-u套的上游参考和git知道从哪里fetch/ pull和在哪里push的未来.

  • 它只是整个地址的缩写。您可以给它起任何名称,但如果只有一个远程地址,大多数人都会将其称为“origin”。您应该阅读[此](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes);-) (2认同)
  • 您不需要复制任何内容!你为什么要这么做? (2认同)
  • 我强烈建议您阅读[this](https://git-scm.com/docs).如果某些事情仍然不清楚,只需在SO上写一个问题;-)开始另一个教程是没有意义的. (2认同)

pro*_*sti 5

现在可以在不键入命令行的情况下从VS Code设置原点:

git remote add origin https://github.com/USR/REPO.git
Run Code Online (Sandbox Code Playgroud)

在VS Code中,如果您使用的是Windows,则可以CTRL+ SHIFT+ 。Premote

从那里选择,Git: Add Remote然后您将有两个步骤:


Von*_*onC 5

来自评论

VSCode 不支持其 UI 中的“添加远程”操作(2018 年 4 月)

实际上,从Visual Studio Code 1.46(2020 年 5 月)开始就是这样:

从 GitHub 添加远程

现在,您可以使用 Git: Add Remote... 命令轻松将 GitHub 存储库作为远程存储库添加到本地存储库。

https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_46/git-add-remote.gif

  • 在它对我的 git 项目进行自动完成后,我选择它并按 Enter 键。然后它再次提示我空白编辑框。没有消息。只是不工作。 (4认同)