[英]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
,您将有两个步骤:
origin
for the remote name:origin
远程名称:origin
URL: https://github.com/USR/REPO.gitorigin
地址: https : //github.com/USR/REPO.gitVSCode 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 存储库作为远程存储库添加到本地存储库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.