
目錄

1. 本地配置github
- 配置你的名字和Email地址
git config --global user.name "<Your Name>"
git config --global user.email "<you@example.com>"
例如:
git config --global user.name "54yimeng"
git config --global user.email "54zifeng@gmail.com"

提示:
- 注意更換內(nèi)容
- 禁止git自動(dòng)將LF轉(zhuǎn)化成CRLF
git config --global core.autocrlf false


- 生成.ssh
ssh-keygen -t rsa -C "<Your github username>"

提示:
- 注意更換為你的github賬戶名.
- 配置.ssh

- 測(cè)試ssh
ssh -T git@github.com

- 查看本地配置
git config -l

2. 首次提交項(xiàng)目
- 我的測(cè)試項(xiàng)目
test(在桌面上)

- github新建一個(gè)倉庫為
test

- 項(xiàng)目中打開Git Bash

- 初始化項(xiàng)目
git init

- 將項(xiàng)目上所有的文件添加到倉庫中
git add *

- 對(duì)這次提交進(jìn)行注釋
git commit -m "Update"

- 獲得倉庫地址

- 將本地的倉庫關(guān)聯(lián)github對(duì)應(yīng)的倉庫
git remote add origin <倉庫地址>
例如:
git remote add origin https://github.com/54yimeng/test.git

- 先將github倉庫代碼與本地合并
git pull origin master --allow-unrelated-histories

提示:
- 為什么要執(zhí)行這步?
因?yàn)槲以趧?chuàng)建倉庫時(shí),用描述進(jìn)行了初始化,所以github的倉庫不為空. 兩個(gè)根本不相干的 git 庫,一個(gè)是本地庫,一個(gè)是遠(yuǎn)端庫,然后本地要去推送到遠(yuǎn)端, 遠(yuǎn)端覺得這個(gè)本地庫跟自己不相干, 所以告知無法合并.,參閱 git 出現(xiàn) fatal: refusing to merge unrelated histories 錯(cuò)誤.
- 代碼上傳到github倉庫
git push -u origin master

- 查看test倉庫

- 查看配置
git config -l

3. 以后提交項(xiàng)目
- 進(jìn)入項(xiàng)目文件夾打開git bash
git add *
git commit -m "Update"
git pull origin master
git push origin master
參閱:
更新中......