1. 程式人生 > >使用git上傳程式碼到GitHub

使用git上傳程式碼到GitHub

閱讀本節前請確認兩點:a)有GitHub賬號;b)本地已成功安裝git工具。

Windows鍵+R調出黑視窗,使用命令上傳程式碼到GitHub倉庫。

1.檢視git版本

C:\Users\xxx>git --version
git version 2.8.1.windows.1

2.檢視git配置

C:\Users\xxx>git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/javasoftwear/Git-2.8.1-64-bit/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
credential.helper=manager
user.name=lankk1
[email protected]
credential.helper=manager

3.進入原生代碼目錄

C:\Users\xxx>cd C:\gitupload

C:\gitupload>DIR
 驅動器 C 中的卷是 OS
 卷的序列號是 9C07-D1DE

 C:\gitupload 的目錄

2018/07/25  11:06    <DIR>          .
2018/07/25  11:06    <DIR>          ..
2018/07/25  11:06    <DIR>          main
               0 個檔案              0 位元組
               3 個目錄 105,449,271,296 可用位元組

C:\gitupload>

4.將程式碼所在的目錄設定為本地git倉庫

C:\gitupload>git init
Initialized empty Git repository in C:/gitupload/.git/

5. 將程式碼新增至本地git倉庫

C:\gitupload>git add .        # .表示新增本目錄下的所有檔案
warning: LF will be replaced by CRLF in main/webapp/WEB-INF/web.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in main/webapp/index.jsp.
The file will have its original line endings in your working directory.

6. 提交到本地git倉庫

C:\gitupload>git commit -m 測試用            # 提交,-m後加備註資訊
[master (root-commit) 423306b] 測試用
warning: LF will be replaced by CRLF in main/webapp/WEB-INF/web.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in main/webapp/index.jsp.
The file will have its original line endings in your working directory.
 7 files changed, 35 insertions(+)
 create mode 100644 main/java/demo/lankk1/controller/WebsocketController.java
 create mode 100644 main/java/demo/lankk1/service/WebsocketService.java
 create mode 100644 main/java/demo/lankk1/service/impl/WebsocketServiceImpl.java
 create mode 100644 main/resources/spring/spring-mvc.xml
 create mode 100644 main/resources/spring/spring-service.xml
 create mode 100644 main/webapp/WEB-INF/web.xml
 create mode 100644 main/webapp/index.jsp

7.關聯遠端倉庫

C:\gitupload>git remote add origin https://github.com/lankk1/devOne

C:\gitupload>

 

 8.拾取遠端倉庫的變化,這樣能在提交remote前保持本地和remote的內容一致。

C:\gitupload>git pull origin master
warning: no common commits
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 13 (delta 0), reused 5 (delta 0), pack-reused 8
Unpacking objects: 100% (13/13), done.
From https://github.com/lankk1/devOne
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Merge made by the 'recursive' strategy.
 README.md | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 README.md

9.提交給remote倉庫

 提交時注意要輸入賬號和密碼。

C:\gitupload>git push origin master
Fatal: HttpRequestException encountered.
Fatal: TaskCanceledException encountered.
Username for 'https://github.com': lankk1            # 輸入賬號
Password for 'https://[email protected]':            # 輸入密碼
Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (21/21), 1.75 KiB | 0 bytes/s, done.
Total 21 (delta 0), reused 0 (delta 0)
To https://github.com/lankk1/devOne
   d171cdd..0f5731c  master -> master