简体   繁体   English

Visual Studio Code - 连接到远程 Git 存储库并将本地文件推送到新的远程存储库

[英]Visual Studio Code - Connect to a remote Git repository and PUSH local files to a new remote repository

I have created a local project with Visual Studio Code that implements a local Git repository .我已经使用 Visual Studio Code 创建了一个本地项目,该项目实现了本地 Git 存储库

Then I have create a Git repository on Visual Studio Online and I want to push all my project files to the remote repository...然后我在Visual Studio Online上创建了一个 Git 存储库,我想所有项目文件送到远程存储库...

What is the correct procedure to do it?执行此操作的正确程序是什么?

My .git\\config files at this moment look like this:此时我的.git\\config文件如下所示:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true

I assume you started to work in a directory and didn't use Git there.我假设你开始在一个目录中工作并且没有在那里使用 Git。 The following should work with Git Bash :以下应该适用于Git Bash

cd "path to your repository"
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...

To add a remote, just do要添加遥控器,只需执行

git remote add origin https://...
git remote show origin # If everything is ok, you will see your remote
git push -u origin master # Assuming you are on the master branch.

The -u sets an upstream reference and Git knows from where to fetch / pull and where to push in the future. -u设置上游引用,Git 知道从哪里fetch / pull fetch以及将来从哪里push

It is now possible to set the origin from Visual Studio Code without command line typing:现在可以在不键入命令行的情况下从 Visual Studio Code 设置原点:

git remote add origin https://github.com/USR/REPO.git

From within Visual Studio Code you may Ctrl + SHIFT + P if you are on Windows and type remote .在 Visual Studio Code 中,如果您在 Windows 上,您可以Ctrl + SHIFT + P并键入remote

From there select Git: Add Remote and you will have two steps:从那里选择Git: Add Remote ,您将有两个步骤:

From comments : 来自评论

VSCode does not support the "add remote" action in its UI (April 2018) VSCode 不支持其 UI 中的“添加远程”操作(2018 年 4 月)

Actually, it does since Visual Studio Code 1.46 (May 2020) :实际上,它从Visual Studio Code 1.46(2020 年 5 月)开始

Add remote from GitHub从 GitHub 添加远程

You can now easily add a GitHub repository as a remote to your local repositories using the Git: Add Remote... command.您现在可以使用 Git: Add Remote... 命令轻松地将 GitHub 存储库作为远程存储库添加到本地存储库。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 中将本地存储库推送到远程? - How to push local repository to remote in Visual Studio? 如何将已建立的本地git存储库链接到新的远程存储库并将所有文件推送到远程? - How do I link an already established local git repository to a new remote repository and push all files to remote? 如何将现有的本地 git 存储库连接到 Visual Studio 2013 中的现有远程存储库? - How to connect an existing local git repository to its existing remote repository in Visual Studio 2013? 无法将文件推送到本地 Git 服务器上的远程 git 存储库 - Not able to push files to remote git repository on local Git server git:删除本地分支上的文件后,推送到远程存储库 - git: push to remote repository, after deleting files on local branch Visual Studio 2015和GIT-使用本地登台覆盖远程存储库 - Visual Studio 2015 & GIT - Overwrite remote repository with local staging 使用<git push>在 Visual Studio Code 上,但显示“无法从远程存储库读取”。 - To use <git push> on Visual Studio Code, but show "Could not read from remote repository." 无法将 git 本地 master 推送到远程仓库 - Unable to push git local master to remote repository 创建一个远程git仓库并从本地推送 - Create a remote git repository and push from local git push 不将本地更改提交到远程存储库 - git push not submitting local changes to remote repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM