Git一些簡單但非常重要并常用的操作命令
1.將本地與github進行關(guān)聯(lián)配置
生成公鑰
ssh-keygen -t rsa -C "jiasheng.mei@hpe.com"
將公鑰拷貝到github中
在公鑰同文件夾(.ssh)下創(chuàng)建config文件,文件內(nèi)容
Host ssh.github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
生成公鑰后將公鑰配置到github上
將github上的項目clone到本地
git clone git@github.com:jiashengp/test.git
在本地init一個git項目
git init
修改了文件后添加
git add .
commit并寫commit注釋
git commit -m "commit text"
將本地和github庫關(guān)聯(lián)
git remote add origin git@github.com:jiashengp/test.git
如果出現(xiàn)fatal: remote origin already exists.則直接進行下面語句
git push origin master
給你的隊友創(chuàng)建一個分支
- git branch cjun
- git add .
- git commit -m "Create cjun branch give chengjun"
同步到github上
- git push -u origin cjun
這時你可以在github上看到為隊友創(chuàng)建的分支
查看分支:git branch
切換分支:git checkout newBranch
你的隊友在github上改了readme.md,你需要同步到本地的git倉庫
將github上cjun分支的下載到臨時的分支temp
- git fetch origin cjun:temp
看下同一個文件你和你的隊友有啥區(qū)別
- git diff temp (在那個分支下,就是這個分支和temp比較)
合并temp分支到本地的master分支(也可以是其他分支)
- git merge temp
把臨時分支干掉
- git branch -D temp
其實上面等價:
git pull origin cjun:temp

浙公網(wǎng)安備 33010602011771號