git獲取默認遠端倉庫的其他分支
Lenovo-E4430:~/code/monitor_alert$ git branch -a
* master
remotes/origin/develop
remotes/origin/master
Lenovo-E4430:~/code/monitor_alert$ git checkout develop
Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'
Lenovo-E4430:~/code/monitor_alert$ git branch
* develop
master
git上fork別人代碼後如何與原代碼保持同步
#fork項目後與原項目進行同步
#首先clone自己
git clone https://github.com/xx.git
#添加遠程倉庫
git remote add username-xx https://github.com/xx.git
git fetch username-xx
git merge username-xx/master ----也可以選擇其他遠程分支
#如果有衝突則需要手動解決衝突,
git commit -m "merge from username-xx"
git push -u origin master ---也可以選擇其他分支操作
#查看本地倉庫
git remote -v
git branch -a
將遠程分支拉到本地並建立本地和遠端的映射
git remote add remote-name https://github.com/xx.git
git checkout -b local_branch remote-name/remote_branch
git branch -vv
本地分支切換
git checkout local-branch-name
git刪除本地分支和遠程分支
#刪除本地分支
git branch -d branch-name
#刪除遠程分支
#冒號前面的空格不能少,原理是把一個空分支push到遠程上,相當於刪除該分支
git push origin :branch-name
git查看某個文件的修改歷史
git log --pretty=oneline filename
輸入上面命令後,會得到改文件修改歷史的sha-1值,然後輸入下面的命令查看具體修改了什麼內容:
git show sha-1