Git本地分支关联远程分支

Git本地分支关联远程分支

本地分支相关操作

  • 查看本地分支

    shell 复制代码
    git branch
  • 新建本地分支

    shell 复制代码
    git branch name
  • 切换本地分支

    shell 复制代码
    git checkout name
  • 新建本地分支并切换到该分支

    shell 复制代码
    git checkout -b name 
    #或
    git branch name
  • 删除本地分支

    shell 复制代码
    git branch -d name
    git branch -D name #强制删除

远程分支相关操作

  • 查看远程和本地所有分支

    shell 复制代码
    git branch -a
  • 新建远程分支

    shell 复制代码
    git checkout -b localname #首先在本地新建分支
    git push origin localname:remotename #将本地分支同步到远程,完成新建远程分支
  • 本地分支连接远程分支

    shell 复制代码
    git branch --set-upstream-to=origin/remotename
    #或
    git branch -u origin/remotename
  • 根据远程分支新建本地分支

    shell 复制代码
    git checkout -b name origin/remotename
    #或
    git branch --set-upstream-to=origin/remotename localname
  • 删除远程分支(慎重

    shell 复制代码
    git push origin :remotename
    #或
    git push origin --delete remotename
相关推荐
Irene19912 小时前
查看是否已安装 Git 的方法
git
my_power5202 小时前
检出git项目到android studio该如何配置
android·git·android studio
安果移不动2 小时前
Git 实战:如何优雅地撤销历史中的某一个 Commit?
git
啥都不懂的小小白5 小时前
Git 入门指南:从零开始掌握版本控制
git
AI逐月5 小时前
Git 彻底清除历史记录
大数据·git·elasticsearch
有什么东东6 小时前
Windows安装git教程以及初步使用
git
不爱吃米饭_6 小时前
Gitea 轻量级的Git方案 - Gitlab的替代品
git·gitlab·gitea
CoderJia程序员甲9 小时前
GitHub 热榜项目 - 日榜(2025-12-15)
git·ai·开源·llm·github
大柏怎么被偷了10 小时前
【Git】远程操作
git
studytosky10 小时前
Linux 基础开发工具(3):Git 控制与 GDB 调试实用指南
linux·运维·服务器·网络·数据库·git