git 新建分支合并指定分支到远程仓库

256 阅读2分钟

一:导向:

在项目中很多小伙伴都会遇到不想在当前分支开发,因为会有很多的问题发生,如果我新建一个测试的分支 ,是不是效率就提高了,把测试没有问题的代码合并到主分支上,是不是就解决了?版本的修复,不同功能的测试修改,都可以用的到下面我把我的经验分享一下。

1. 当前修改后代码上传远程仓库

首先

git add .


git commit -m "将本地代码上传远程仓库"

git push
//会发现当前错误???
To 10.3.9.116:zuxiangyun/hktk_MiXin.git
 ! [rejected]        dev_weixin -> dev_weixin (non-fast-forward)
error: failed to push some refs to 'git@10.3.9.116:zuxiangyun/hktk_MiXin.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
先不用管

2. 新建业务分支(新建一个分支) git checkout -b

使用创建 feat_1 分支并切换git checkout -b feat_1

 git checkout -b feat_1

3. 切换到新建的分支

切换到新建的分支(如果当前没有分支如何新建分支呢?)

 // 新建分支分支并切换
 git checkout -b  feat_1
 // 切换分支
 git checkout feat_1
 // 查看分支
 git branch

4.切换新建的分支

切换到我们新建的分支(新建的分支名:feat_1)

   git checkout feat_1// (新分支)

5. (指定)分支的代码(将指定分支或要处理的分支代码进行拉取) merge

我们将(指定)分支的代码 merge 到自己的分支上

 merge // 合并分支使用
   
git merge dev_weixin(自定义小程序处理业务分支)
  

6.处理业务分支代码仓库同步(合并)

git push推送到远程仓库和处理业务分支代码仓库仓库同步(合并)

 如果当前使用git push 
错误标识:当前分支没有与远程分支关联,因此导致了提交代码失败
// MacBook-Pro-5:web-crm feate_weixin_localup$ git push
fatal: The current branch wangxiao has no upstream branch.
To push the current branch and set the remote as upstream, use
   git push --set-upstream origin feate_weixin_localup

6.1 最强暴的方法

最强暴的方法:使用该命令强制提交到远程分支
git push --set-upstream origin feate_weixin_localup

7.1如果当前已经执行完成上面的全部过程也就是完成远程提交的全部流程

如果想切换分支切记要
git add .

git commit -m "暂存本地"

git checkout dev_weixin