git 分支管理 推送本地分支到远程分支

git 分支管理 推送本地分支到远程分支等

<div class="article-info-box">
    <div class="article-bar-top d-flex">
                                            <span class="time">2015年08月03日 12:23:50</span>
        <div class="float-right">
            <span class="read-count">阅读数:55223</span>
                                        </div>
    </div>
</div>
<article>
    <div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
                <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/htmledit_views-0a60691e80.css">
        <div class="htmledit_views">

1、创建本地分支 local_branch

     git branch local_branch


2、创建本地分支local_branch 并切换到local_branch分支

   git checkout -b local_branch


3、切换到分支local_branch

    git checkout local_branch


4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系

      a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch

          git push

     b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch

         git push -u origin/remote_branch

     c.远程没有有remote_branch分支并,本地已经切换到local_branch

        git push origin local_branch:remote_branch

5、删除本地分支local_branch

      git branch -d local_branch

6、删除远程分支remote_branch

     git push origin  :remote_branch

     git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。

   git branch -d | -D branchname 删除branchname分支

   git branch -d -r branchname 删除远程branchname分支


7、查看本地分支

      git branch


8、查看远程和本地分支

      git branch -a


      

   

        </div>
            </div>
        </article>

    <div class="article-bar-bottom">
                            <div class="tags-box">
        <span class="label">个人分类:</span>
                    <a class="tag-link" href="https://blog.youkuaiyun.com/hijiankang/article/category/5704191" target="_blank">git                        </a>
    </div>
                </div>

<!-- !empty($pre_next_article[0]) -->
    </div>
Git 中,将本地分支推送远程仓库的相应分支是一个常见的操作。如果本地分支已经与远程分支建立了跟踪关系,可以使用简单的 `git push` 命令完成推送。如果没有建立跟踪关系,则需要指定远程仓库和远程分支。 ### 推送本地分支远程分支的基本操作 #### 1. **推送指定本地分支远程分支** 如果你希望将本地的某个分支推送远程仓库的特定分支,可以使用以下命令: ```bash git push <remote-name> <local-branch-name>:<remote-branch-name> ``` 例如,要将本地的 `some-branch` 推送远程的 `my-feature` 分支: ```bash git push origin some-branch:my-feature ``` 该操作会将本地 `some-branch` 分支的内容推送远程仓库 `origin` 的 `my-feature` 分支上 [^2]。 #### 2. **建立跟踪关系后推送** 如果本地分支尚未与远程分支建立跟踪关系,可以先使用以下命令设置跟踪关系,然后使用简单的 `git push` 命令进行推送: ```bash git branch --set-upstream-to=origin/<remote-branch-name> <local-branch-name> ``` 例如,将本地的 `battery_modes` 分支远程的 `feature/LINUX-395-develop-battery-kernel-interface-for-custom-charge` 分支建立跟踪关系: ```bash git branch --set-upstream-to=origin/feature/LINUX-395-develop-battery-kernel-interface-for-custom-charge battery_modes ``` 设置完成后,可以直接使用以下命令推送更改: ```bash git push ``` 这种方式适用于经常需要推送和拉取更新的分支 [^3]。 #### 3. **推送所有本地分支远程仓库** 如果需要将所有本地分支推送远程仓库,可以使用以下命令一次性推送所有分支: ```bash git push --all origin ``` 该命令会将本地仓库中的所有分支推送远程仓库 `origin` 中 [^2]。 ### 注意事项 - 在推送分支时,确保远程仓库中已经存在目标分支,否则 Git 会自动创建一个新的远程分支。 - 如果远程分支已经存在且与本地分支有冲突,可能需要先执行 `git pull` 拉取远程分支的最新更改并解决冲突后再推送。 - 使用 `git branch -vv` 可以查看当前本地分支远程分支的跟踪关系。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值