配置SSH,確保push到你github賬號(hào)上的內(nèi)容是你本人操作
1,打開(kāi)Git Bash 輸入:
ssh-keygen -t rsa -C "你的email"
2,復(fù)制主目錄下.ssh文件下的id-rsa.pub里面的內(nèi)容
3,打開(kāi)github 找到SSH Key 點(diǎn)擊Add SSH Key,填上title之后將內(nèi)容粘貼到Key里面;
本地倉(cāng)庫(kù)和遠(yuǎn)程倉(cāng)庫(kù)關(guān)聯(lián)并推送
第一種,本地存在要關(guān)聯(lián)的文件夾
創(chuàng)建一個(gè)空的文件夾,之后:
1,git init
2,可以向文件填寫(xiě)內(nèi)容
3,git add .
4,git commit -m "描述"
5,git remote add origin https://github.com/lovinglili/li.git
6,git push -u origin master//將本地庫(kù)當(dāng)前分支master推送到遠(yuǎn)程庫(kù),第一次push使用-u 之后再提交可簡(jiǎn)化掉
注意:如果遠(yuǎn)程創(chuàng)建倉(cāng)庫(kù)時(shí)候勾選了Initialize this repository with a README,則在push之前 要:git pull --rebase origin master;將遠(yuǎn)端的readme.md文件拉下來(lái);
第二種,將遠(yuǎn)端倉(cāng)庫(kù)克隆下來(lái)
1,復(fù)制github給你的克隆碼
2,git clone https://github.com/lovinglili/mybloog.git //克隆倉(cāng)庫(kù)myblooog到本地
3,修改內(nèi)容
4,git add .
5,git commit -m "描述"
6,git push origin master
本地分支和遠(yuǎn)程分支關(guān)聯(lián)
第一種,本地創(chuàng)建分支提交到遠(yuǎn)程
1,git branch aaa;
2,git push origin aaa;
3,git checkout aaa;
4,創(chuàng)建文件,修改文件等操作
5,git push origin aaa;//內(nèi)容會(huì)提交上去
//步驟5之前可以git merge將aaa分支的內(nèi)容合并到master中,直接push origin master,此時(shí)可將分支aaa刪掉
第二種遠(yuǎn)程創(chuàng)建,拉到本地
1,git checkout --track origin/bbb //錯(cuò):fatal: 'origin/bbb' is not a commit and a branch 'bbb' cannot be created from it
2,git fetch origin//同步數(shù)據(jù)
3,git checkout --track origin/bbb //無(wú)錯(cuò)誤
4,之后就同第一種的步驟4以及其之后的操作
結(jié)言
本地倉(cāng)庫(kù)和遠(yuǎn)程倉(cāng)庫(kù)關(guān)聯(lián)的兩種方法和分支關(guān)聯(lián)的兩種方法可隨意搭配