使用git把程式碼上傳到github
建立倉庫
- 註冊GitHub帳號,通過郵箱驗證
- 在GitHub建立倉庫
-
點選右方的“new repository”按鈕建立一個倉庫
image
- Repository name框取一個名字
- 點選Create repository完成建立
-
安裝git
- ofollow,noindex">https://git-scm.com/downloads 下載並安裝git
- ubuntu可以使用命令
sudo apt-get install git
- ubuntu可以使用命令
設定ssh key
1. 建立使用者名稱和密碼
git config --global user.name "hello" git config --global user.email "[email protected]"
2. 生成ssh金鑰
輸入命令:
ssh-keygen -t rsa -C "[email protected]"
- 此處郵箱為github的郵箱
連續按三個回車:
Generating public/private rsa key pair. Enter file in which to save the key (/home/xuanli/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/xuanli/.ssh/id_rsa. Your public key has been saved in /home/xuanli/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Fn9I3+UV3NxeMQT4G75KyMjNteTrfxuU+8PSjF1Bkr0 [email protected] The key's randomart image is: +---[RSA 2048]----+ |..**+| |. o +B| |. . . o.=| |+ o + E+| |S oo+ +oo| |..= =..o. o| |o = +Bo.| |. .+ Bo| |.+o.o.+| +----[SHA256]-----+
出現類似這樣的提示代表金鑰建立完成。
Your public key has been saved in /home/xuanli/.ssh/id_rsa.pub.
指定了金鑰存放位置
3. 新增到github
- 開啟github,點選頭像,選擇settings

image
- 選擇SSH and GPG keys

image
-
點選new SSH key
-
title隨便填寫,複製id_rsa.pub中的內容,到key中

image
- 點選 Add SSH key
4.檢測是否成功
輸入命令
ssh -T [email protected]
輸入yes,如果HI之後的名字是你github的使用者名稱的話說明成功
上傳程式碼到github
進入專案根目錄
1.初始化本地倉庫
輸入命令
git init
這個命令會在當前目錄建立一個 .git 的檔案
2.新增檔案到暫存區
git add .
.
代表所有,也可以指定檔名
3.將暫存區檔案提交到倉庫區
git commit -m '版本描述'
- -m 後邊跟得是版本描述
4.建立關聯地址
git remote add origin [email protected]:XXX/XXX.git
- origin 後為github倉庫的地址,要選擇ssh地址而不是https地址

image
5.上傳到github
git push -u origin master
上面命令將本地的master分支推送到origin主機,同時指定origin為預設主機。
到現在為止,便上傳完成。