天天看點

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,友善查閱

最終效果如下:

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

步驟

1.GIT軟體安裝

現在并安裝​​GIT​​

我們這裡使用

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

通過指令行的方式将本地項目托管到GITHUB。

2.初始化本地maven項目為 Git 項目

本地項目目錄: D:\workspace\workspace-sts\SpringMaster

打開GIT BASH,進入到項目所在目錄

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

執行指令

$ git init      
Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

此時會在目錄中建立一個 .git 隐藏檔案夾,如下

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

3.将所有檔案放進新的本地 git 倉庫

$ git add .      
Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

如果你本地已經有 ​

​.gitignore​

​​ 檔案,會按照已有規則過濾不需要添加的檔案。如果不想要添加所有檔案,可以把 ​

​.​

​ 符号換成具體的檔案名

4. 将添加的檔案送出到倉庫

git commit -m "Initial commit"      
Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

5. GitHub上建立項目 ,copy項目位址

建立過程省略,最後如下所示:

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

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.git

Mr.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​

​指令檢視結果

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

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.      
Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

8. Github上檢視項目

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

Github提示資訊

倉庫建立成功後,Github如下提示資訊,可以指導我們将項目托管到GITHUB 倉庫

…or create a new repository on the command line

echo "# 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 line

git 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.      
Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

9. 在Spring Tool Suite中連接配接GITHUB

Windows—Show View選擇Git Repositories

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

選擇 Add an existing local Git Repository to this view

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

選擇本地的GIT項目

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

切換到GIT視圖 或者Spring視圖 都可以看到了

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

檔案操作,右鍵 Team

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

或者下載下傳一個GitHub Desktop

File-Add local Repository

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

如下

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

選擇你要操作的項目即可

Git-将已有的項目轉換為GIT項目托管到 GITHUB 倉庫

或者直接使用指令行的方式最為友善。

另外一個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 commit
 18 files changed, 438 insertions(+)
 create mode 100644 .classpath
 create mode 100644 .project
 create mode 100644 .settings/org.eclipse.core.resources.prefs
 create mode 100644 .settings/org.eclipse.jdt.core.prefs
 create mode 100644 .settings/org.eclipse.m2e.core.prefs
 create mode 100644 pom.xml
 create mode 100644 src/main/java/com/artisan/commonUtils/App.java
 create mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtil.java
 create mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtilDemo.java
 create mode 100644 src/main/java/com/artisan/commonUtils/mail/MailServer.properties
 create mode 100644 src/main/java/com/artisan/commonUtils/mail/SendEmailUtil.java
 create mode 100644 src/test/java/com/artisan/commonUtils/AppTest.java
 create mode 100644 target/classes/com/artisan/commonUtils/App.class
 create mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtil.class
 create mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtilDemo.class
 create mode 100644 target/classes/com/artisan/commonUtils/mail/MailServer.properties
 create mode 100644 target/classes/com/artisan/commonUtils/mail/SendEmailUtil.class
 create mode 100644 target/test-classes/com/artisan/commonUtils/AppTest.class

Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git remote add origin https://github.com/yangshangwei/commonUtils.git

Mr.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)
$