# 上傳代碼到github
## 創建倉庫
1. 注冊GitHub帳號,通過郵箱驗證
2. 在GitHub創建倉庫
1. 點擊右方的“new repository”按鈕創建一個倉庫

2. Repository name框取一個名字
3. 點擊Create repository完成創建
## 安裝git
1. [https://git-scm.com/downloads](https://git-scm.com/downloads)下載并安裝git
- ubuntu可以使用命令 `sudo apt-get install git`
## 設置ssh key
### 1. 創建用戶名和密碼
```
git config --global user.name "hello"
git config --global user.email "hello@163.com"
```
### 2. 生成ssh密鑰
輸入命令:
```
ssh-keygen -t rsa -C "hello@163.com"
```
- 此處郵箱為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 hello@163.com.com
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

- 選擇SSH and GPG keys

- 點擊new SSH key
- title隨便填寫,復制id_rsa.pub中的內容,到key中

- 點擊 Add SSH key
### 4.檢測是否成功
輸入命令
```
ssh -T git@github.com
```
輸入yes,如果HI之后的名字是你github的用戶名的話說明成功
## 上傳代碼到github
進入項目根目錄
### 1.初始化本地倉庫
輸入命令
```
git init
```
這個命令會在當前目錄創建一個 .git 的文件
### 2.添加文件到暫存區
```
git add .
```
`.`代表所有,也可以指定文件名
### 3.將暫存區文件提交到倉庫區
```
git commit -m '版本描述'
```
- -m 后邊跟得是版本描述
### 4.創建關聯地址
```
git remote add origin git@github.com:XXX/XXX.git
```
- origin 后為github倉庫的地址,要選擇ssh地址而不是https地址

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