Git branch

git 分支的管理

1.git clone : 克隆分支(默认master)

ysqdeMacBook-Pro:www ysq$ git clone https://github.com/lollicupusa/lollicupStore2.git

2. git clone -b sun-dev : 克隆指定的分支代码

ysqdeMacBook-Pro:www ysq$ git clone -b sun-dev https://github.com/lollicupusa/lollicupStore2.git
Cloning into 'lollicupStore2'...
Username for 'https://github.com': 421072757@qq.com
Password for 'https://421072757@qq.com@github.com': 
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 51111 (delta 2), reused 18 (delta 1), pack-reused 51074
Receiving objects: 100% (51111/51111), 2.33 GiB | 2.66 MiB/s, done.
Resolving deltas: 100% (20079/20079), done.
Checking out files: 100% (44341/44341), done.
ysqdeMacBook-Pro:www ysq$ ls
lollicupStore2
ysqdeMacBook-Pro:www ysq$ cd  lollicupStore2/
ysqdeMacBook-Pro:lollicupStore2 ysq$ ls
404.shtml			configSnippets			green.png			php.ini.bk
............
cmsBlocks			google4df796f9ca21dcb7.html	php.ini
ysqdeMacBook-Pro:lollicupStore2 ysq$ git branch
* sun-dev
ysqdeMacBook-Pro:lollicupStore2 ysq$ 

3. git branch -r :查看远程分支:

ysqdeMacBook-Pro:lollicupStore2 ysq$ git branch -r
  origin/HEAD -> origin/master
  origin/aaron
  origin/add-customer-info-to-feedback
  origin/alex
  origin/apiInventory
  origin/brandbanner
  origin/hc_api
  origin/hcll
  origin/master
  origin/order-approval
  origin/sharry
  origin/store-review-reward-plugin
  origin/storex
  origin/sun-dev
ysqdeMacBook-Pro:lollicupStore2 ysq$ 

4. git branch -a :查看所有的分支:

ysqdeMacBook-Pro:lollicupStore2 ysq$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/aaron
  remotes/origin/add-customer-info-to-feedback
  remotes/origin/alex
  remotes/origin/apiInventory
  remotes/origin/brandbanner
  remotes/origin/hc_api
  remotes/origin/hcll
  remotes/origin/master
  remotes/origin/order-approval
  remotes/origin/sharry
  remotes/origin/store-review-reward-plugin
  remotes/origin/storex
  remotes/origin/sun-dev

5. git checkout -b : 根据远程分支 克隆到自己的本地:

ysqdeMacBook-Pro:lollicupStore2 ysq$ git checkout -b sun-dev origin/sun-dev

6. git checkout :切换分支:

$ git checkout sun-dev

7. git branch :查看当前本地所有的分支

$ git branch
  master
  qiu
* storex
  sun-dev

8. git merge :合并分支(需要合并的分支名称;storex), 切换到自己的分支,然后合并分支 。

格式: merge 后面跟上自己需要合并的哪个分支: 例如:合并storex

LOLLICUP@DESKTOP-EF95EEJ MINGW64 /d/www/20181024master/yang (sun-dev)
$ git merge storex

9 . git checkout -b 分支名称(sun-dev) 根据默认克隆的远程主分支,创建自己的开发分支(即在当前所在分支上创建一个新分支)

ysqdeMacBook-Pro:www ysq$ git clone https://github.com/lollicupusa/lollicupStore2.git lollicup
Cloning into 'lollicup'...
Username for 'https://github.com': 421072757@qq.com
Password for 'https://421072757@qq.com@github.com': 
remote: Enumerating objects: 109, done.
remote: Counting objects: 100% (109/109), done.
remote: Compressing objects: 100% (82/82), done.
remote: Total 51449 (delta 13), reused 91 (delta 12), pack-reused 51340
Receiving objects: 100% (51449/51449), 2.38 GiB | 1.89 MiB/s, done.
Resolving deltas: 100% (20163/20163), done.
Checking out files: 100% (44802/44802), done.
ysqdeMacBook-Pro:www ysq$ ls
lollicup	lollicupStore2
ysqdeMacBook-Pro:www ysq$ cd lollicup
ysqdeMacBook-Pro:lollicup ysq$ git branch
* master
ysqdeMacBook-Pro:lollicup ysq$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   media/customer/P/e/Permit.jpg
	modified:   media/customer/R/e/Resale_Certificate.pdf
	modified:   media/customer/R/e/Reseller_Permit.pdf
	modified:   media/customer/S/E/SELLER_PERMIT.pdf
	modified:   media/customer/S/e/Seller_Permit.pdf
	modified:   media/customer/S/e/Seller_s_Permit.pdf
	modified:   media/customer/S/e/Sellers_Permit.pdf

no changes added to commit (use "git add" and/or "git commit -a")
ysqdeMacBook-Pro:lollicup ysq$ git checkout -b sun-dev
M	media/customer/P/e/Permit.jpg
M	media/customer/R/e/Resale_Certificate.pdf
M	media/customer/R/e/Reseller_Permit.pdf
M	media/customer/S/E/SELLER_PERMIT.pdf
M	media/customer/S/e/Seller_Permit.pdf
M	media/customer/S/e/Seller_s_Permit.pdf
M	media/customer/S/e/Sellers_Permit.pdf
Switched to a new branch 'sun-dev'
ysqdeMacBook-Pro:lollicup ysq$ git branch
  master
* sun-dev
ysqdeMacBook-Pro:lollicup ysq$ 

10. 删除远程分支:git push origin :分支名称(注意origin后面有一个空格)在开发过程中,大家在远程创建了许多分支,有些是无用的,该如何删除呢,

git push  [远程名] :[分支名]。如果想在服务器上删 

除 sun-dev 分支,运行下面的命令:

ysqdeMacBook-Pro:lollicup ysq$ git branch -r
  origin/HEAD -> origin/master
  origin/aaron
  origin/add-customer-info-to-feedback
  origin/alex
  origin/apiInventory
  origin/brandbanner
  origin/commerce
  origin/hc_api
  origin/hcll
  origin/master
  origin/order-approval
  origin/sharry
  origin/store-review-reward-plugin
  origin/storex
  origin/sun-dev
ysqdeMacBook-Pro:lollicup ysq$ git push origin :sun-dev
Username for 'https://github.com': 421072757@qq.com
Password for 'https://421072757@qq.com@github.com': 
To https://github.com/lollicupusa/lollicupStore2.git
 - [deleted]           sun-dev
ysqdeMacBook-Pro:lollicup ysq$ git branch -r
  origin/HEAD -> origin/master
  origin/aaron
  origin/add-customer-info-to-feedback
  origin/alex
  origin/apiInventory
  origin/brandbanner
  origin/commerce
  origin/hc_api
  origin/hcll
  origin/master
  origin/order-approval
  origin/sharry
  origin/store-review-reward-plugin
  origin/storex
ysqdeMacBook-Pro:lollicup ysq$ 

11. 将自己的本地分支发布到远程仓库创建分支

ysqdeMacBook-Pro:lollicup ysq$ git push --set-upstream origin sun-dev
Username for 'https://github.com': 421072757@qq.com
Password for 'https://421072757@qq.com@github.com': 
Total 0 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'sun-dev' on GitHub by visiting:
remote:      https://github.com/lollicupusa/lollicupStore2/pull/new/sun-dev
remote: 
To https://github.com/lollicupusa/lollicupStore2.git
 * [new branch]        sun-dev -> sun-dev
Branch 'sun-dev' set up to track remote branch 'sun-dev' from 'origin'.
ysqdeMacBook-Pro:lollicup ysq$ git branch -r
  origin/HEAD -> origin/master
  origin/aaron
  origin/add-customer-info-to-feedback
  origin/alex
  origin/apiInventory
  origin/brandbanner
  origin/commerce
  origin/hc_api
  origin/hcll
  origin/master
  origin/order-approval
  origin/sharry
  origin/store-review-reward-plugin
  origin/storex
  origin/sun-dev
ysqdeMacBook-Pro:lollicup ysq$ 

Leave a comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注