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
相关推荐
A_Lonely_Cat2 天前
记一次 GitHub 幽灵协作者大清洗:强制重写 Git 历史与穿透 CDN 缓存实践
git·github
和你看星星4 天前
Git rerere:让重复冲突只解决一次
git
嘻嘻仙人8 天前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github
Patrick_Wilson8 天前
Squash Merge 的血缘陷阱:为什么删掉的代码又活了过来
前端·git·程序员
沉浸学习的匿名网友8 天前
什么是 .gitignore?为什么每个 Git 项目几乎都离不开它?
前端·git
深海鱼在掘金9 天前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森9 天前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang9 天前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年10 天前
Windows 中安装 git
git
深海鱼在掘金15 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git