[](https://996.icu)
1,git clone .. ?克隆遠程分支到本地。
2,git checkout branchName 在本地切換分支 ?
? ? ? git checkout -b branchName? // create and checkout a new branch
? ? ? git check out -t branchName // --trackset upstream info for new branch
? ? ? git checkout -h // 查看git checkout 幫助
3,git commit 提交本地改動
? ? ? git commit -m'some change' // 提交本地改動到本地倉庫
? ? ? git commit -a // 提交本地全部改動到本地(需謹慎操作)
4,git push origin developer 推送本地倉庫改動到遠程倉庫
? ? ? git push origin branchName // 該遠程分支創(chuàng)建
? ? ? git push origin -u branchName // 該遠程分支未創(chuàng)建時使用
5,git merge 合并分支
? ? ?git fetch origin developer // 從遠程的origin倉庫的developer主分支更新最新的版本到當前分支上
? ? ?git log -p branchName..origin/developer // 比較本地的branchName分支和origin/developer分支的差別
? ? ?git merge origin/developer // 合并內容到本地當前分支
? ? ?git pull // 相當于git fetch 和 git merge,即更新遠程倉庫的代碼到本地倉庫,然后將內容合并到當前分支。
6,常見操作
? ? ? git add 添加文件
? ? ? git add . 添加所有文件
? ? ? git stash //把本次自己的代碼改動暫存起來
? ? ? git pull origin Developer //拉取遠程最新的代碼到本地,(相當于git fetch 和 git merge)
? ? ? git stash pop //恢復第一步暫存的代碼,這時候如果代碼中有沖突需手動解決
? ? ? git rm --cache '文件名' // 有時不想刪除本地的文件, 只是想讓git不再track, 這時可以使用 git rm --cached 文件路徑
7,Github 上怎樣把新 commits 使用在自己的 fork 上:
? ? ? 1、配置上游項目地址。即將你 fork 的項目的地址給配置到自己的項目上。比如我 fork 了一個項目,原項目是 wabish/fork-demo.git,我的項目就是 cobish/fork-demo.git。使用以下命令來配置。
? ? ?? git remote add upstream https://github.com/wabish/fork-demo.git
? ? ? 然后可以查看一下配置狀況,很好,上游項目的地址已經被加進來了。
? ? ?? git remote -vorigin? git@github.com:cobish/fork-demo.git(fetch)origin? git@github.com:cobish/fork-demo.git(push)upstream? ? https://github.com/wabish/fork-demo.git(fetch)upstream? ? https://github.com/wabish/fork-demo.git(push)
? ? ? 2、獲取上游項目更新。使用 fetch 命令更新,fetch 后會被存儲在一個本地分支 upstream/master 上。
? ? ? ? git fetch upstream
? ? ? 3、合并到本地分支。切換到 master 分支,合并 upstream/master 分支。
? ? ? ? git merge upstream/master
? ? ? 4、從遠程倉庫同步到 自己fork后的倉庫 (同步分支等)
? ? ? ??git remote update
鏈接:https://www.zhihu.com/question/20393785/answer/105370502
參考資料:http://www.zhanglian2010.cn/2014/07/git-pull-vs-fetch-and-merge/
? ? ? ? ? ? ? ? ? https://www.oschina.net/translate/git-fetch-and-merge?cmp&p=1#
? ? ? ? ? ? ? ? ? http://www.itdecent.cn/p/ae4857d2f868 // 如何從從detached HEAD狀態(tài)解救出來
