一、生成密鑰
郵箱地址填自己的github賬號(hào)育拨,連續(xù)按三次enter匕坯,不需要
$ ssh-keygen -t rsa -C "your email@.com"
查看公鑰
cat ~/.ssh/id_rsa.pub
github上配置好公鑰后可通過以下命令查看是否成功
$ ssh -T git@github.com
二、設(shè)置全局配置
設(shè)置git全局用戶名
git config --global user.name "lufei"
設(shè)置git全局郵箱
git config --global user.email "lufei@qq.com"
查看配置
git config --list
三蛉威、拉取遠(yuǎn)程倉庫代碼到本地
拉取遠(yuǎn)程倉庫代碼到本地
git clone https://github.com/firefly66/test.git
查看文件
ls
四材蛛、把代碼上傳到git遠(yuǎn)程倉庫
添加某個(gè)文件
git add "test.js"
添加全部
git add .
添加說明
git commit -m "first"
推送到遠(yuǎn)程分支默認(rèn)分支main
git push -u origin main
五、創(chuàng)建分支
和遠(yuǎn)程倉庫連接
git remote add origin "remote_url"
查看分支
git branch -a(查看所有分支包括本地分支和遠(yuǎn)程分支)
git branch -r(查看遠(yuǎn)程分支)
紅色為遠(yuǎn)程倉庫的分支怎抛,黑色卑吭、綠色為本地分支,綠色為當(dāng)前所在分支
切換分支
git checkout main
git checkout -b branchname(直接新建一個(gè)分支然后切換至新創(chuàng)建的分支)就是創(chuàng)建加切換分支.
價(jià)于命令:git branch branchname+git checkout branchname
git checkout branchname(是切換分支名).
刪除本地分支马绝,刪除分支需要切換到其他分支再刪除該分支
git branch -d branchname
將新分支推送至GitHub.
git push origin branchname
六豆赏、查看暫存區(qū)文件
git ls-files 命令是用來查看暫存區(qū)中文件信息
常用參數(shù)
參數(shù)說明(括號(hào)里是簡寫)
--cached(-c)顯示暫存區(qū)中的文件,git ls-files命令默認(rèn)的參數(shù)
--deleted(-d)顯示刪除的文件
--modified(-m) 顯示修改過的文件
--other(-o)顯示沒有被git跟蹤的文件
--stage(-s) 顯示mode以及文件對(duì)應(yīng)的Blob對(duì)象富稻,進(jìn)而我們可以獲取暫存區(qū)中對(duì)應(yīng)文件里面的內(nèi)容掷邦。
七 分支關(guān)聯(lián)遠(yuǎn)程倉庫
本地分支關(guān)聯(lián)遠(yuǎn)程倉庫才能pull
$git branch --set-upstream-to=origin/dev
八 其他
遠(yuǎn)程新建了倉庫,本地檢測(cè)不到椭赋,需要刷新一下啊
git remote update origin --prune
拉取制定分支不是master
git clone -b dev https:xxxxxx
遠(yuǎn)程倉庫地址改變
git remote set-url origin "new url"
檢出指定舊版本
git reset --hard xxxxx
本地檢出的分支提交到特定分支
git push origin local_branch:remote_branch
強(qiáng)制更新
git push origin remote_branch -f
git push origin dev:master -f
忽略某個(gè)文件夾 不進(jìn)行版本控制
創(chuàng)建.gitignore文件,例如
unpackage/
.DS_Store
如果之前已經(jīng)提交過到遠(yuǎn)程倉庫抚岗,需執(zhí)行
git rm -r --cached unpackage
- 本地分支推送到新的遠(yuǎn)端分支(遠(yuǎn)端分支沒有將新建)
git push origin local_branch:remote_branch