git 操作命令記錄

一、clone Repository

git clone [email protected]:FBing/design-patterns.git

二、
1、查看分支
A、查看本地分支
使用 git branch命令,如下:

$ git branch
* master

*標識的是你當前所在的分支。

B、查看遠程分支
命令如下:

git branch -r
C、查看所有分支
命令如下:

git branch -a


2、本地創建新的分支
命令如下:

git branch [branch name]
例如:

git branch gh-dev
3、切換到新的分支
命令如下:

git checkout [branch name]

例如:

$ git checkout gh-dev
Switched to branch 'gh-dev'

4、創建+切換分支
創建分支的同時切換到該分支上,命令如下:

git checkout -b [branch name]

git checkout -b [branch name] 的效果相當於以下兩步操作:

git branch [branch name]
git checkout [branch name]

5、將新分支推送到github
命令如下:

git push origin [branch name]

例如:

git push origin gh-dev

6、刪除本地分支
命令如下:

git branch -d [branch name]

例如:

git branch -d gh-dev

7、刪除github遠程分支
命令如下:

git push origin :[branch name]

分支名前的冒號代表刪除。
例如:

git push origin :gh-dev

三、git提交本地代碼到新分支
1、切換到新的分支
命令如下:

git checkout [branch name]

例如:

$ git checkout gh-dev
Switched to branch 'gh-dev'

2、添加本地需要提交代碼
命令如下:

git add .

3、提交本地代碼
命令如下:

git commit -m "add my code to new branchB"

4、push 到git倉庫
命令如下:

git push origin [branch name]

例如:

git push origin gh-dev

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章