VS代码如何在现有本地项目中使用github

VS代码如何在现有本地项目中使用github,github,Github,我在C:\ABC文件夹中有一个本地项目,只是意识到是时候将它备份到GitHub了。这就是我所做的: 登录GitHub,创建一个新的项目存储库或任何您需要的东西 我可以打电话。 复制URL。 回到VS代码,安装GitHub扩展。 转到欢迎页面,单击克隆Git存储库。。。。粘贴URL 用于存储库URL。输入我的本地路径C:\ABC。 错误Git:fatal:目标路径C:\ABC已存在且不存在 空目录 我知道它试图从GitHub获取本地数据,但我想要的恰恰相反。Google找到了许多关于如何从头开始的

我在C:\ABC文件夹中有一个本地项目,只是意识到是时候将它备份到GitHub了。这就是我所做的:

登录GitHub,创建一个新的项目存储库或任何您需要的东西 我可以打电话。 复制URL。 回到VS代码,安装GitHub扩展。 转到欢迎页面,单击克隆Git存储库。。。。粘贴URL 用于存储库URL。输入我的本地路径C:\ABC。 错误Git:fatal:目标路径C:\ABC已存在且不存在 空目录


我知道它试图从GitHub获取本地数据,但我想要的恰恰相反。Google找到了许多关于如何从头开始的文章和视频,但不适用于现有的本地项目。

尝试使用命令行:

cd c:\ABC
git init .
git config --global user.name <yourGitHubAccount>
git config --global user.email <yourGitHubEmailAccount>
git add .

git status
# edit .gitignore to ignore folder you don't want

git commit -m "first commit"
git remote add origin https://github.com/<yourGitHubAccount>/<yourRepo.git>
git push -u origin master

确保您的GitHub repo实际上为空无自述。md

@VonC,重新执行相同的步骤: 1创建一个新的本地空目录,在VS代码中将本地空目录链接到GitHub的空存储库,如所述。成功了

2使用我的代码文件/目录填充此本地空目录

3 git init。 系统消息:重新初始化现有Git存储库…/.Git/

3一次运行一个命令,没有错误或消息

git config --global user.name Jeb50 
git config --global user.email Jeb50@XYZ.com
4吉特加起来。 系统消息:

warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Angular/Modules/mainApp.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in content/Site.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   .vscode/launch.json
        new file:   Angular/Controllers/AuthController.js
        new file:   Angular/Controllers/MainController.js
        new file:   Angular/Models/user.js
        new file:   Angular/Modules/mainApp.js
        new file:   Passport/passport-init.js
        new file:   Routes/authentication.js
        new file:   Routes/routerMEAN2.js
        new file:   Untitled.png
        new file:   Views/Authentication/login.html
        new file:   Views/Authentication/register.html
        new file:   Views/Authentication/unauth.html
        new file:   Views/Main/About.html
        new file:   Views/Main/Contact.html
        new file:   Views/Main/index.html
        new file:   Views/Starter.ejs
        new file:   content/Site.css
        new file:   package-lock.json
        new file:   package.json
        new file:   server.js
[master (root-commit) f8e435e] first commit
 21 files changed, 2305 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .vscode/launch.json
 create mode 100644 Angular/Controllers/AuthController.js
 create mode 100644 Angular/Controllers/MainController.js
 create mode 100644 Angular/Models/user.js
 create mode 100644 Angular/Modules/mainApp.js
 create mode 100644 Passport/passport-init.js
 create mode 100644 Routes/authentication.js
 create mode 100644 Routes/routerMEAN2.js
 create mode 100644 Untitled.png
 create mode 100644 Views/Authentication/login.html
 create mode 100644 Views/Authentication/register.html
 create mode 100644 Views/Authentication/unauth.html
 create mode 100644 Views/Main/About.html
 create mode 100644 Views/Main/Contact.html
 create mode 100644 Views/Main/index.html
 create mode 100644 Views/Starter.ejs
 create mode 100644 content/Site.css
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 server.js
fatal: remote origin already exists.
Counting objects: 34, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 30.77 KiB | 0 bytes/s, done.
Total 34 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/TLKG/MEAN2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
5吉特状态 系统消息:

warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Angular/Modules/mainApp.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in content/Site.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   .vscode/launch.json
        new file:   Angular/Controllers/AuthController.js
        new file:   Angular/Controllers/MainController.js
        new file:   Angular/Models/user.js
        new file:   Angular/Modules/mainApp.js
        new file:   Passport/passport-init.js
        new file:   Routes/authentication.js
        new file:   Routes/routerMEAN2.js
        new file:   Untitled.png
        new file:   Views/Authentication/login.html
        new file:   Views/Authentication/register.html
        new file:   Views/Authentication/unauth.html
        new file:   Views/Main/About.html
        new file:   Views/Main/Contact.html
        new file:   Views/Main/index.html
        new file:   Views/Starter.ejs
        new file:   content/Site.css
        new file:   package-lock.json
        new file:   package.json
        new file:   server.js
[master (root-commit) f8e435e] first commit
 21 files changed, 2305 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .vscode/launch.json
 create mode 100644 Angular/Controllers/AuthController.js
 create mode 100644 Angular/Controllers/MainController.js
 create mode 100644 Angular/Models/user.js
 create mode 100644 Angular/Modules/mainApp.js
 create mode 100644 Passport/passport-init.js
 create mode 100644 Routes/authentication.js
 create mode 100644 Routes/routerMEAN2.js
 create mode 100644 Untitled.png
 create mode 100644 Views/Authentication/login.html
 create mode 100644 Views/Authentication/register.html
 create mode 100644 Views/Authentication/unauth.html
 create mode 100644 Views/Main/About.html
 create mode 100644 Views/Main/Contact.html
 create mode 100644 Views/Main/index.html
 create mode 100644 Views/Starter.ejs
 create mode 100644 content/Site.css
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 server.js
fatal: remote origin already exists.
Counting objects: 34, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 30.77 KiB | 0 bytes/s, done.
Total 34 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/TLKG/MEAN2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
7git commit-m first commit,看起来还可以,但存储库下没有显示任何代码 系统消息:

warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Angular/Modules/mainApp.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in content/Site.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   .vscode/launch.json
        new file:   Angular/Controllers/AuthController.js
        new file:   Angular/Controllers/MainController.js
        new file:   Angular/Models/user.js
        new file:   Angular/Modules/mainApp.js
        new file:   Passport/passport-init.js
        new file:   Routes/authentication.js
        new file:   Routes/routerMEAN2.js
        new file:   Untitled.png
        new file:   Views/Authentication/login.html
        new file:   Views/Authentication/register.html
        new file:   Views/Authentication/unauth.html
        new file:   Views/Main/About.html
        new file:   Views/Main/Contact.html
        new file:   Views/Main/index.html
        new file:   Views/Starter.ejs
        new file:   content/Site.css
        new file:   package-lock.json
        new file:   package.json
        new file:   server.js
[master (root-commit) f8e435e] first commit
 21 files changed, 2305 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .vscode/launch.json
 create mode 100644 Angular/Controllers/AuthController.js
 create mode 100644 Angular/Controllers/MainController.js
 create mode 100644 Angular/Models/user.js
 create mode 100644 Angular/Modules/mainApp.js
 create mode 100644 Passport/passport-init.js
 create mode 100644 Routes/authentication.js
 create mode 100644 Routes/routerMEAN2.js
 create mode 100644 Untitled.png
 create mode 100644 Views/Authentication/login.html
 create mode 100644 Views/Authentication/register.html
 create mode 100644 Views/Authentication/unauth.html
 create mode 100644 Views/Main/About.html
 create mode 100644 Views/Main/Contact.html
 create mode 100644 Views/Main/index.html
 create mode 100644 Views/Starter.ejs
 create mode 100644 content/Site.css
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 server.js
fatal: remote origin already exists.
Counting objects: 34, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 30.77 KiB | 0 bytes/s, done.
Total 34 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/TLKG/MEAN2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
8 git远程添加源https://github.com/Jeb50/MEAN2.git 系统消息:

warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Angular/Modules/mainApp.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in content/Site.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   .vscode/launch.json
        new file:   Angular/Controllers/AuthController.js
        new file:   Angular/Controllers/MainController.js
        new file:   Angular/Models/user.js
        new file:   Angular/Modules/mainApp.js
        new file:   Passport/passport-init.js
        new file:   Routes/authentication.js
        new file:   Routes/routerMEAN2.js
        new file:   Untitled.png
        new file:   Views/Authentication/login.html
        new file:   Views/Authentication/register.html
        new file:   Views/Authentication/unauth.html
        new file:   Views/Main/About.html
        new file:   Views/Main/Contact.html
        new file:   Views/Main/index.html
        new file:   Views/Starter.ejs
        new file:   content/Site.css
        new file:   package-lock.json
        new file:   package.json
        new file:   server.js
[master (root-commit) f8e435e] first commit
 21 files changed, 2305 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .vscode/launch.json
 create mode 100644 Angular/Controllers/AuthController.js
 create mode 100644 Angular/Controllers/MainController.js
 create mode 100644 Angular/Models/user.js
 create mode 100644 Angular/Modules/mainApp.js
 create mode 100644 Passport/passport-init.js
 create mode 100644 Routes/authentication.js
 create mode 100644 Routes/routerMEAN2.js
 create mode 100644 Untitled.png
 create mode 100644 Views/Authentication/login.html
 create mode 100644 Views/Authentication/register.html
 create mode 100644 Views/Authentication/unauth.html
 create mode 100644 Views/Main/About.html
 create mode 100644 Views/Main/Contact.html
 create mode 100644 Views/Main/index.html
 create mode 100644 Views/Starter.ejs
 create mode 100644 content/Site.css
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 server.js
fatal: remote origin already exists.
Counting objects: 34, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 30.77 KiB | 0 bytes/s, done.
Total 34 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/TLKG/MEAN2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
9 git推送-u源主机 系统消息:

warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Angular/Modules/mainApp.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in content/Site.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   .vscode/launch.json
        new file:   Angular/Controllers/AuthController.js
        new file:   Angular/Controllers/MainController.js
        new file:   Angular/Models/user.js
        new file:   Angular/Modules/mainApp.js
        new file:   Passport/passport-init.js
        new file:   Routes/authentication.js
        new file:   Routes/routerMEAN2.js
        new file:   Untitled.png
        new file:   Views/Authentication/login.html
        new file:   Views/Authentication/register.html
        new file:   Views/Authentication/unauth.html
        new file:   Views/Main/About.html
        new file:   Views/Main/Contact.html
        new file:   Views/Main/index.html
        new file:   Views/Starter.ejs
        new file:   content/Site.css
        new file:   package-lock.json
        new file:   package.json
        new file:   server.js
[master (root-commit) f8e435e] first commit
 21 files changed, 2305 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .vscode/launch.json
 create mode 100644 Angular/Controllers/AuthController.js
 create mode 100644 Angular/Controllers/MainController.js
 create mode 100644 Angular/Models/user.js
 create mode 100644 Angular/Modules/mainApp.js
 create mode 100644 Passport/passport-init.js
 create mode 100644 Routes/authentication.js
 create mode 100644 Routes/routerMEAN2.js
 create mode 100644 Untitled.png
 create mode 100644 Views/Authentication/login.html
 create mode 100644 Views/Authentication/register.html
 create mode 100644 Views/Authentication/unauth.html
 create mode 100644 Views/Main/About.html
 create mode 100644 Views/Main/Contact.html
 create mode 100644 Views/Main/index.html
 create mode 100644 Views/Starter.ejs
 create mode 100644 content/Site.css
 create mode 100644 package-lock.json
 create mode 100644 package.json
 create mode 100644 server.js
fatal: remote origin already exists.
Counting objects: 34, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 30.77 KiB | 0 bytes/s, done.
Total 34 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/TLKG/MEAN2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
在GitHub刷新代码选项卡,将显示预期的文件。看起来很有效

太棒了


以下是我使用SourceTree将现有文件夹/项目从VSCode添加到GitHub的解决方案:

在GitHub上创建回购。创建后,您可以创建.gitignore或在步骤3中手动执行此操作。 在命令行的项目根目录中,键入以下命令以将此项目初始化为Git repo:Git init 如果在步骤1的repo中尚未创建.gitignore,请在根目录中手动为特定项目创建.gitignore,确保忽略所有相关文件,即web项目的节点_模块。最好从Github中的现有模板复制已完成的 打开SourceTree并按“克隆/新建” 选择“添加工作副本选项卡” 在“工作副本路径”中,使用省略号查找在步骤1中初始化Git项目的根目录。您将知道您做得很正确,因为在对话框中的“Repository Type”旁边,您将看到一条消息,其中指出,这是一个Git存储库。关闭对话框。 转到右上角的“设置”并“添加”遥控器。 假设默认设置,“名称”为“来源”,选择“默认远程”,并为URL/路径输入在步骤1中创建repo时提供的完整GitHub路径。按OK。即https://github.com/MyUserName/MyCoolCode.git 转移并提交您的文件 将主分支推到“原点” 我承认,我认为GitHub提供的用于初始化repo和执行第一次提交的命令行指令更容易。然而,此时,您的GitHub repo在SourceTree中已正确连接,可以开始了


我还想说,如果你能提前考虑,在做任何工作之前,创建一个空的repo并在SourceTree中克隆它会容易得多。这肯定是从第一天开始最容易跟踪的。但是,上述步骤对于添加现有解决方案非常有效。

此解决方案可能很蹩脚,但对我来说却很有魅力

1登录GitHub,创建一个与您的项目类似的存储库。 2复制URL。 3开放VS代码将存储库克隆到本地使用。 这可以通过按command+p来实现,这将打开一个输入框。 在输入框中写入克隆并选择克隆。 粘贴git存储库url并选择任何要克隆的空目录。 4打开本地项目,将除.git文件夹之外的所有内容复制并粘贴到克隆的存储库中。 5现在在VS代码中打开新的克隆项目。 6进入查看>供应链管理 7在输入中输入一些注释,例如初始提交。 8单击检查图标,选择是并输入一些消息。
9单击“检查”按钮之外的SCM选项三个点并发布分支。

我只需单击三次即可使用github桌面应用程序完成此操作:

关键方向是:您可以将任何Git存储库添加到GitHub桌面,即使它不是GitHub存储库

它将识别该目录不是一个repo,并询问您是否要创建一个repo

单击“创建回购”后,您将看到:

最后,它甚至会提示您将其发布到Github进行备份:


@我在分支主机初始提交未跟踪文件时得到的VoC:.gitignore.vscode/Angular/。。。server.jsbottom屏幕显示提交时没有添加任何内容,只有未跟踪的文件present@Jeb50你什么时候收到这些信息?键入哪个命令后?是的。无法添加到注释中。错误来自git commit-m first commit。刚刚发现。还有另一种方法可以
去做吧。1下载并安装GitHub Desktop v 0.8.0。2使用此应用程序登录以连接到GitHub。3文件,添加本地存储库。还没有机会,希望桌面能正常工作。GitHub很棒,但也有一些困惑,好的是花一些时间学习一些新的东西。它奏效了。Thnks