我比較笨,喜歡簡(jiǎn)單粗暴的??傮w來(lái)說(shuō)就是干三件事:
- 建立本地倉(cāng)庫(kù),建立github倉(cāng)庫(kù)
- 建立本地倉(cāng)庫(kù)與github網(wǎng)站的連接,為本地倉(cāng)庫(kù)管理員(就是我)授權(quán),能夠pull(從github取回資源)還能push(把我本地倉(cāng)庫(kù)的東東放到github中備份)
- 初始化git,配置git,進(jìn)行push 和pull
1.1 建立本地倉(cāng)庫(kù)
比如我現(xiàn)在用vim的markdown寫個(gè)筆記
mkdir yuan_note
cd yuan_note
然后巴拉巴拉往里面放了很多東西,這就是我的本地倉(cāng)庫(kù),一個(gè)文件夾,搞定啦!
1.2 建立github倉(cāng)庫(kù)
當(dāng)然是申請(qǐng)個(gè)賬號(hào)了,有了賬號(hào)之后,點(diǎn)擊右上角加號(hào),New repository

2.1 建立兩者連接
首先申請(qǐng)個(gè)ssh (security shell),先到根目錄創(chuàng)建ssh文件夾,然后創(chuàng)建.ssh
cd
mkdir .ssh
ssh-keygen -t rsa -C "你的github郵箱"

copy ssh鑰匙
pbcopy <~/.ssh/id_rsa.pub
在你的github網(wǎng)址,右上角頭像,setting點(diǎn)進(jìn)去 SSH and GPG keys -》New SSH key
Title 隨便起一個(gè),比如郵箱+一些標(biāo)識(shí), key里面,把剛才復(fù)制的粘貼進(jìn)去

然后把證書和github關(guān)聯(lián),測(cè)試連接
ssh -T git@github.com
然后輸入yes

如果有問題,github有很多幫助找錯(cuò)誤的
https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey
https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories
以上就是給我的github配個(gè)鎖,然后我這里有個(gè)ssh的鑰匙可以開鎖的過程。
2.2 為本地倉(cāng)庫(kù)管理員(就是我)授權(quán)
git config --global user.name "隨便起個(gè)名字"
git config --global user.email "我的github郵箱"
3. 初始化git,配置git,進(jìn)行push 和pull
cd yuan_note
git init
git add .
git commit -m "添加的備注"
git remote add my_origin https://github.com/XXXX/yuan_note.git //你剛才創(chuàng)建的github的repository,以https開頭以.git結(jié)尾的
//0. 這時(shí)候可以檢測(cè)一下你的remote倉(cāng)庫(kù)也就是上一步設(shè)置的是否正確
git remote -v
//0.1 如果設(shè)置錯(cuò)誤了
git remote remove my_origin
// 1. 取回資源,從剛才設(shè)置的my_origin 的master分支取回?cái)?shù)據(jù)到這個(gè)文件夾中
git pull --rebase https://github.com/XXXX/yuan_note.git
//或者直接
git pull my_origin
Git在202012后將不支持使用密碼push,如果大家直接
git push my_origin master會(huì)發(fā)現(xiàn)報(bào)錯(cuò)為
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information
這時(shí)候需要在github----setting----1. [Developer settings]----Personal access tokens-----Generate new token

然后把他copy下來(lái),記作密碼YYA
再輸入
//2. 將本地(本地就是剛才git init這個(gè)文件夾)push到github備份,將這個(gè)文件夾的數(shù)據(jù)發(fā)射到剛才設(shè)置的my_origin的master分支中取
git push -u my_origin main
//Username for 'https://github.com':
//Password for 'https://yzmhust@gmai.com@github.com': [輸入剛才copy的密碼YYA]
就可以了!