如何把已存在的 project 上傳到 Github ref to https://git-scm.com/book/zh-tw/v1 完整手冊 https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ ---------- github網站 = https://github.com/ 方法1: 盡量使用GitHub 1. 在github網站上Create a new repository. 例如: (Repository name = MVCLab0030, Public, Add .gitignore=VisualStudio). 2. 啟動GitShell (Git Bash), CD到原專案目錄. 例如: cd D:\GitHub\MVCLab\Lab0030\MVBase\. 3. 建立Git repository. 輸入git init. 執行後可以用檔案總管可以看到新增了隱藏目錄. 例如: D:/GitHub/MVCLab/Lab0030/MVCBase/.git/. 4. 到github網站上複製專案網址. 例如: https://github.com/github-honda/MVCLab0030.git. 5. 新增專案網址. 輸入git remote add origin [URL]. 例如: git remote add origin https://github.com/github-honda/MVCLab0030.git. 6. 確認專案網址. 輸入git remote -v. 7. 開啟GitHub, 執行Add repository, local path選擇剛剛建立的repository, 例如: D:/GitHub/MVCLab/Lab0030/MVCBase. 8. 選擇上方Changes, 可以看到專案檔案需要Commit to master. 在Changes網頁下方Summary欄位輸入: First commit後, 再按最下方的Commit to master. 畫面執行結果為No local changes. 9. 選擇上方History, 再按右上方的Publish ---------- 方法1: 搭配使用GitHub 1. 在github網站上Create a new repository. 例如: (Repository name = MVCLab0030, Public, Add .gitignore=VisualStudio). 2. 啟動GitShell (Git Bash), CD到原專案目錄. 例如: cd D:\GitHub\MVCLab\Lab0030\MVBase\. 3. 建立Git repository. 輸入git init. 用檔案總管可以看到新增了隱藏目錄. 例如: D:/GitHub/MVCLab/Lab0030/MVCBase/.git/. 4. 加入所有local檔案為first commit到local repository. 輸入"git add .". 將所有的檔案都變成 first commit. 5. 存入local repository. 輸入"git commit -m 'First commit'". 6. 到github網站上複製專案網址. 例如: https://github.com/github-honda/MVCLab0030.git. 7. 新增專案網址. 輸入git remote add origin [URL]. 例如: git remote add origin https://github.com/github-honda/MVCLab0030.git. 8. 確認專案網址. 輸入git remote -v. 9. 開啟GitHub, 執行Add repository, local path選擇剛剛建立的repository, 例如: D:/GitHub/MVCLab/Lab0030/MVCBase. 10. 執行Publish. 將所有local檔案公開到github網站(Publich master to remote). 執行結果可以在github網站上repository根目錄下, 看到Visual Studio的solution檔案與專案目錄. 例如: MVCBase.sln與目錄MVCBase. 問題注意: Q1. Visual Studio Source Control之Plug-In Selection改選擇Git無效, 會自動恢復為AnhkSVN - Subversion Support for Visual Studio Q2. AnhkSVN - Subversion Support for Visual Studio已安裝時, git介面在Visual Studio中無效! 必須用GitHub管理. ---------- 3. 開啟GitHub, 執行clone repository. 例如: (repository name=MVCLab0030, D:\GitHub\MVCLab\Lab0030\MVBase\ 這方法不行! repository 名稱不是預期的結果! ---------- 方法2: 使用指令, 但最後一個動作需要靠GitHub 主要是參考這一篇Github官網的教學: Adding an existing project to GitHub using the command line 1. 先在Github上創建一個新的 repository 1.1 記得要選.gitignore為Visual Studio 1.2 .gitattributes要如何加入? 2. 接著打開Git Bash,cd到那個project所在的資料夾 3. 輸入"git init",把它initial 成一個 Git repository 4. 輸入"git add .",將所有的檔案都變成 first commit 5. 輸入"git commit -m 'First commit' ",Commit the files 6. 去Github那邊,把repository的網址(URL)複製起來 Copy remote repository URL field 7. 輸入"git remote add origin URL",設定新的URL 8. 輸入"git remote -v",確認URL 9. 輸入"git push origin master",並輸入 Username 和 Password 最後這一步驟改用GitHub UI操作: 9.1 重新執行GitHub. 注意如果已經啟動, 則必須重新啟動! 9.2 publish 專案所有檔案 9.3 Sync一次, 同步server跟client的所有檔案! 問題注意: 1 Visual Studio Source Control之Plug-In Selection改選擇Git無效, 會自動恢復為AnhkSVN - Subversion Support for Visual Studio 2 AnhkSVN - Subversion Support for Visual Studio已安裝時, git介面在Visual Studio中無效! 必須用GitHub管理. 接著到Github上的repository看,就可以發現你的project被放到Github上囉! Windows PowerShell 著作權 (C) 2015 Microsoft Corporation. 著作權所有,並保留一切權利。 C:\Users\honda_000\Documents\GitHub> d: D:\> cd github D:\github> dir 目錄: D:\github Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2016/9/22 上午 09:33 dygraphs d----- 2016/9/14 下午 06:52 GroupViewModelSample d----- 2016/10/4 上午 10:36 MVCLab d----- 2015/2/21 下午 08:18 SignalrRxDemo d----- 2016/9/15 上午 08:33 Test1 D:\github> cd mvclab D:\github\mvclab> dir 目錄: D:\github\mvclab Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2016/10/4 下午 04:56 Lab0010 d----- 2016/10/4 上午 10:35 Lab0020 d----- 2016/10/4 上午 10:35 Lab0030 d----- 2016/10/4 上午 10:35 Lab0040 d----- 2016/10/4 上午 10:35 Lab0050 d----- 2016/10/4 上午 10:35 Lab0060 d----- 2016/10/4 上午 10:35 Lab0070 d----- 2016/10/4 上午 10:35 Lab0080 d----- 2016/10/4 上午 10:35 Lab0090 d----- 2016/10/4 上午 10:35 Lab0100 d----- 2016/10/4 上午 10:35 Lab0110 d----- 2016/10/4 上午 10:35 Lab0120 d----- 2016/10/4 上午 10:35 Lab0130 d----- 2016/10/4 上午 10:35 Lab0140 d----- 2016/10/4 上午 10:35 Lab0150 D:\github\mvclab> cd lab0010 D:\github\mvclab\lab0010> dir 目錄: D:\github\mvclab\lab0010 Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2016/10/4 下午 11:14 MVCBase D:\github\mvclab\lab0010> cd mvcbase D:\github\mvclab\lab0010\mvcbase> dir 目錄: D:\github\mvclab\lab0010\mvcbase Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2016/10/4 上午 10:36 MVCBase d----- 2016/10/4 下午 11:12 MVCLab0010 d----- 2016/10/4 下午 11:14 packages -a---- 2016/8/31 下午 03:27 1134 MVCBase.sln D:\github\mvclab\lab0010\mvcbase> dir 目錄: D:\github\mvclab\lab0010\mvcbase Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2016/8/31 下午 03:27 MVCBase -a---- 2016/8/31 下午 03:27 1134 MVCBase.sln D:\github\mvclab\lab0010\mvcbase> git init Initialized empty Git repository in D:/GitHub/MVCLab/Lab0010/MVCBase/.git/ D:\github\mvclab\lab0010\mvcbase [master +2 ~0 -0 !]> git add . warning: LF will be replaced by CRLF in MVCBase/Content/bootstrap.css. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Content/bootstrap.min.css. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/bootstrap.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/bootstrap.min.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/jquery-1.10.2.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/jquery-1.10.2.min.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/jquery.validate.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/jquery.validate.min.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/jquery.validate.unobtrusive.min.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/modernizr-2.6.2.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/respond.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/Scripts/respond.min.js. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in MVCBase/fonts/glyphicons-halflings-regular.svg. The file will have its original line endings in your working directory. D:\github\mvclab\lab0010\mvcbase [master +47 ~0 -0 ~]> git commit -m 'First commit' [master (root-commit) 2f61aa5] First commit 47 files changed, 30904 insertions(+) create mode 100644 MVCBase.sln create mode 100644 MVCBase/App_Start/BundleConfig.cs create mode 100644 MVCBase/App_Start/FilterConfig.cs create mode 100644 MVCBase/App_Start/RouteConfig.cs create mode 100644 MVCBase/ApplicationInsights.config create mode 100644 MVCBase/Content/Site.css create mode 100644 MVCBase/Content/bootstrap.css create mode 100644 MVCBase/Content/bootstrap.min.css create mode 100644 MVCBase/Controllers/HomeController.cs create mode 100644 MVCBase/Global.asax create mode 100644 MVCBase/Global.asax.cs create mode 100644 MVCBase/MVCBase.csproj create mode 100644 MVCBase/Project_Readme.html create mode 100644 MVCBase/Properties/AssemblyInfo.cs create mode 100644 MVCBase/Scripts/_references.js create mode 100644 MVCBase/Scripts/ai.0.22.9-build00167.js create mode 100644 MVCBase/Scripts/ai.0.22.9-build00167.min.js create mode 100644 MVCBase/Scripts/bootstrap.js create mode 100644 MVCBase/Scripts/bootstrap.min.js create mode 100644 MVCBase/Scripts/jquery-1.10.2.intellisense.js create mode 100644 MVCBase/Scripts/jquery-1.10.2.js create mode 100644 MVCBase/Scripts/jquery-1.10.2.min.js create mode 100644 MVCBase/Scripts/jquery-1.10.2.min.map create mode 100644 MVCBase/Scripts/jquery.validate-vsdoc.js create mode 100644 MVCBase/Scripts/jquery.validate.js create mode 100644 MVCBase/Scripts/jquery.validate.min.js create mode 100644 MVCBase/Scripts/jquery.validate.unobtrusive.js create mode 100644 MVCBase/Scripts/jquery.validate.unobtrusive.min.js create mode 100644 MVCBase/Scripts/modernizr-2.6.2.js create mode 100644 MVCBase/Scripts/respond.js create mode 100644 MVCBase/Scripts/respond.min.js create mode 100644 MVCBase/Views/Home/About.cshtml create mode 100644 MVCBase/Views/Home/Contact.cshtml create mode 100644 MVCBase/Views/Home/Index.cshtml create mode 100644 MVCBase/Views/Shared/Error.cshtml create mode 100644 MVCBase/Views/Shared/_Layout.cshtml create mode 100644 MVCBase/Views/Web.config create mode 100644 MVCBase/Views/_ViewStart.cshtml create mode 100644 MVCBase/Web.Debug.config create mode 100644 MVCBase/Web.Release.config create mode 100644 MVCBase/Web.config create mode 100644 MVCBase/favicon.ico create mode 100644 MVCBase/fonts/glyphicons-halflings-regular.eot create mode 100644 MVCBase/fonts/glyphicons-halflings-regular.svg create mode 100644 MVCBase/fonts/glyphicons-halflings-regular.ttf create mode 100644 MVCBase/fonts/glyphicons-halflings-regular.woff create mode 100644 MVCBase/packages.config D:\github\mvclab\lab0010\mvcbase [master]> git remote add origin https://github.com/github-honda/MVCLab0010.git D:\github\mvclab\lab0010\mvcbase [master]> git remote -v origin https://github.com/github-honda/MVCLab0010.git (fetch) origin https://github.com/github-honda/MVCLab0010.git (push) D:\github\mvclab\lab0010\mvcbase [master]> git push origin master To https://github.com/github-honda/MVCLab0010.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/github-honda/MVCLab0010.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. D:\github\mvclab\lab0010\mvcbase [master]>