git操作: 删除分支以及合入另一个分支

一、删除分支

在使用git 管理仓库代码的时候,会遇到分支过多难以分辨的苦恼,需要删除部分分支,以下为git 命令:

# 查看本地包含哪些分支以及当前分支,带*为当前分支
git branch
* dev-union-image
  label-layer-count
  master
  pre-merge

# 删除本地分支
git branch -d label-layer-count
Deleted branch label-layer-count (was b812577).

# 若无法删除,使用
git branch -D label-layer-count


# 删除远程分支(!!!慎用)
git push origin --delete label-layer-count
To http://gitlab.com/xxx/yyy.git
 - [deleted]         label-layer-count

二、合入另一分支

在开发过程中,会有开发分支,主干分支,有时候修改代码量过大,页面因为文件限制无法完成合并操作,可以通过命令行修改:

# 从远端新拉分支
git pull
# 切换到源分支
git checkout git-merge-test

# 拉取新分支,git-merge-test02为新分支名
git checkout -b git-merge-test02

# 推送到远端
git push origin git-merge-test02
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To http://gitlab.com/xxx/yyy.git
 * [new branch]      git-merge-test02 -> git-merge-test02

# 从远端更新,显示没有关联本地
git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> git-merge-test01

# 执行 
git branch --set-upstream-to=origin/git-merge-test git-merge-test02

# 再次更新,正常
git pull
Already up to date.

# 更改git-merge-test02 内容并提交远程

# 切换到源分支
git checkout git-merge-test

# git merge
git merge git-merge-test02
Updating e8751f9..15bbef2
Fast-forward
 version-management.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

# 提交远程
git push origin git-merge-test

三、参考文档

1、https://blog.csdn.net/shujuliu818/article/details/121041349

2、https://blog.csdn.net/hello_1995/article/details/119865172

3、https://blog.csdn.net/zl1zl2zl3/article/details/94019526

4、https://www.yiibai.com/git/git_merge.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值