2017-08-26 63 views
1

我在C:\ ABC文件夾中有一個本地項目,只是意識到是時候將它備份到GitHub。這是我做的:VS Code如何在現有的本地項目中使用github

  1. 登錄到GitHub,創建一個新的項目(存儲庫或任何你 可以調用)。
  2. 複製網址。
  3. 返回VS Code,安裝GitHub擴展。
  4. 轉到歡迎頁面,點擊「克隆Git存儲庫...」。將「URL庫」粘貼到URL 。輸入我的本地路徑C:\ ABC,。

錯誤的Git:致命的:目標路徑 「C:\ ABC」 已經存在,而不是 空目錄。

我明白它試圖從GitHub獲取本地,但我想要的是相反的。谷歌搜索發現了許多文章和視頻如何從頭開始,但不是現有的本地項目。

回答

1

嘗試,而不是使用命令行:

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庫實際上是空的(沒有README.md

+0

@VoC我 '分支主 初始提交 未跟蹤的文件:的.gitignore .vscode /角/ ... server.js' – Jeb50

+0

屏幕下方寫着'「沒有加入到承諾,但未跟蹤文件存在」 ' – Jeb50

+0

@ Jeb50你什麼時候有這些消息?輸入哪個命令後? – VonC

1

@VonC,重新做了同樣的步驟: 1)創建一個新的本地空目錄,在VS Code鏈接本地空目錄到GitHub中的空存儲庫(如上所述)。成功了。

2)用我的代碼文件/目錄填充這個本地空目錄。

3)git init . 系統MSG:重新初始化現有Git倉庫.../GIT中/

3)跑這兩個命令一次一個,沒有錯誤也沒有消息。

git config --global user.name Jeb50 
git config --global user.email [email protected] 

4)git add . 系統MSG:

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. 

5)git status 系統MSG:

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 

6)我的。gitignore文件:

# individual files 
9222.jpg 
err1.jpg 
config.js 

# exclude folders 
node_modules/ 

7)git commit -m "first commit",似乎確定,但庫 系統MSG下示出沒有代碼:

[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 

8)git remote add origin https://github.com/Jeb50/MEAN2.git 系統MSG:

fatal: remote origin already exists. 

9) git push -u origin master 系統消息:

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刷新代碼標籤,預期文件出現。似乎工作。

太棒了!

+0

良好的工作和良好的反饋! +1 – VonC

+0

剛發現。還有另一種方式來做到這一點。 1)下載並安裝GitHub Desktop(v 0.8.0)。 2)使用此應用程序登錄連接到GitHub。 3)文件,添加本地存儲庫...。沒有機會,希望桌面將工作。 GitHub很棒,有些困惑,好東西是花一些時間學習新東西。 – Jeb50

相關問題