Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库
文章目錄
- 概述
- 步驟
- 1.GIT軟件安裝
- 2.初始化本地maven項目為 Git 項目
- 3.將所有文件放進新的本地 git 倉庫
- 4. 將添加的文件提交到倉庫
- 5. GitHub上創建項目 ,copy項目地址
- 6. 回到命令行終端界面,將本地倉庫關聯到遠程倉庫
- 7. 提交代碼到 GitHub 倉庫
- 8. Github上查看項目
- Github提示信息
- 9. 在Spring Tool Suite中連接GITHUB
- 另外一個Java項目托管到github上的完整操作
概述
打算將SpringMaster項目托管到GitHub,方便查閱
最終效果如下:
步驟
1.GIT軟件安裝
現在并安裝GIT
我們這里使用通過命令行的方式將本地項目托管到GITHUB。
2.初始化本地maven項目為 Git 項目
本地項目目錄: D:\workspace\workspace-sts\SpringMaster
打開GIT BASH,進入到項目所在目錄
執行命令
$ git init此時會在目錄中創建一個 .git 隱藏文件夾,如下
3.將所有文件放進新的本地 git 倉庫
$ git add .如果你本地已經有 .gitignore 文件,會按照已有規則過濾不需要添加的文件。如果不想要添加所有文件,可以把 . 符號換成具體的文件名
4. 將添加的文件提交到倉庫
git commit -m "Initial commit"5. GitHub上創建項目 ,copy項目地址
創建過程省略,最后如下所示:
https://github.com/yangshangwei/SpringMaster.git 復制倉庫地址
6. 回到命令行終端界面,將本地倉庫關聯到遠程倉庫
Mr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master) $ git remote add origin https://github.com/yangshangwei/SpringMaster.gitMr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master) $ git remote -v origin https://github.com/yangshangwei/SpringMaster.git (fetch) origin https://github.com/yangshangwei/SpringMaster.git (push)通過 git remote -v命令查看結果
7. 提交代碼到 GitHub 倉庫
Mr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master) $ git push -u origin master Counting objects: 590, done. Delta compression using up to 4 threads. Compressing objects: 100% (574/574), done. Writing objects: 100% (590/590), 150.56 KiB | 0 bytes/s, done. Total 590 (delta 180), reused 0 (delta 0) remote: Resolving deltas: 100% (180/180), done. To https://github.com/yangshangwei/SpringMaster.git* [new branch] master -> master Branch master set up to track remote branch master from origin.8. Github上查看項目
Github提示信息
倉庫創建成功后,Github如下提示信息,可以指導我們將項目托管到GITHUB 倉庫
…or create a new repository on the command lineecho "# SpringMaster" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/yangshangwei/SpringMaster.git git push -u origin master…or push an existing repository from the command linegit remote add origin https://github.com/yangshangwei/SpringMaster.git git push -u origin master…or import code from another repository You can initialize this repository with code from a Subversion, Mercurial, or TFS project.9. 在Spring Tool Suite中連接GITHUB
Windows—Show View選擇Git Repositories
選擇 Add an existing local Git Repository to this view
選擇本地的GIT項目
切換到GIT視圖 或者Spring視圖 都可以看到了
文件操作,右鍵 Team
或者下載一個GitHub Desktop
File-Add local Repository
如下
選擇你要操作的項目即可
或者直接使用命令行的方式最為方便。
另外一個Java項目托管到github上的完整操作
打開GitBash
Mr.Yang@Mr MINGW64 ~ $ cd d:Mr.Yang@Mr MINGW64 /d $ cd workspace/ws-java-base/commonUtils/Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils $ git init Initialized empty Git repository in D:/workspace/ws-java-base/commonUtils/.git/Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $ git add .Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $ git commit -m "Intial commit" [master (root-commit) 42fb8f6] Intial commit18 files changed, 438 insertions(+)create mode 100644 .classpathcreate mode 100644 .projectcreate mode 100644 .settings/org.eclipse.core.resources.prefscreate mode 100644 .settings/org.eclipse.jdt.core.prefscreate mode 100644 .settings/org.eclipse.m2e.core.prefscreate mode 100644 pom.xmlcreate mode 100644 src/main/java/com/artisan/commonUtils/App.javacreate mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtil.javacreate mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtilDemo.javacreate mode 100644 src/main/java/com/artisan/commonUtils/mail/MailServer.propertiescreate mode 100644 src/main/java/com/artisan/commonUtils/mail/SendEmailUtil.javacreate mode 100644 src/test/java/com/artisan/commonUtils/AppTest.javacreate mode 100644 target/classes/com/artisan/commonUtils/App.classcreate mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtil.classcreate mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtilDemo.classcreate mode 100644 target/classes/com/artisan/commonUtils/mail/MailServer.propertiescreate mode 100644 target/classes/com/artisan/commonUtils/mail/SendEmailUtil.classcreate mode 100644 target/test-classes/com/artisan/commonUtils/AppTest.classMr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $ git remote add origin https://github.com/yangshangwei/commonUtils.gitMr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $ git remote -v origin https://github.com/yangshangwei/commonUtils.git (fetch) origin https://github.com/yangshangwei/commonUtils.git (push)Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $ git push -u origin master Counting objects: 44, done. Delta compression using up to 4 threads. Compressing objects: 100% (28/28), done. Writing objects: 100% (44/44), 10.15 KiB | 0 bytes/s, done. Total 44 (delta 0), reused 0 (delta 0) To https://github.com/yangshangwei/commonUtils.git* [new branch] master -> master Branch master set up to track remote branch master from origin.Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master) $總結
以上是生活随笔為你收集整理的Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring-AOP 静态普通方法名匹配
- 下一篇: Spring-AOP 静态正则表达式方法