GIT 分支管理

创作人 Leo


编辑时间 Wed Jan 1,2020 at 10:13


GIT 分支管理

创建分支 git 分支,分为本地分支和远程分支

git branch 查看本地分支

git branch -a 查看远程分支

远程分支需要在服务器端建立,然后客户端按照分支检出

本地分支只需执行 “git branch” 或 “ git flow ” 创建即可

git checkout $branch_name 切换到分支

git flow 插件

http://www.berlinix.com/it/gitflow.php

例:创建一个分支

[lixin@web01 interaction]$ git flow init
Which branch should be used for bringing forth production releases?
   - master
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
[lixin@web01 interaction]$ git flow feature start lx_20160701
Switched to a new branch 'feature/lx_20160701'
Summary of actions:
- A new branch 'feature/lx_20160701' was created, based on 'develop'
- You are now on branch 'feature/lx_20160701'
Now, start committing on your feature. When done, use:
     git flow feature finish lx_20160701
[lixin@web01 interaction]$ git branch
  develop
* feature/lx_20160701
  master
[lixin@web01 interaction]$

切换远程分支

git checkout –track origin/….

例:

$ git checkout --track origin/feature/wxlogin_dev
Branch feature/wxlogin_dev set up to track remote branch feature/wxlogin_dev from origin.
Switched to a new branch 'feature/wxlogin_dev'
$ git status
# On branch feature/wxlogin_dev
nothing to commit (working directory clean)
$ git branch -a
  develop
* feature/wxlogin_dev
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/feature/gaozhao
  remotes/origin/feature/wxlogin_dev
  remotes/origin/liaoddhome
  remotes/origin/master
  remotes/origin/remotes/origin/feature/wxlogin_dev
$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@192.168.3.20:system/static.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[gitflow "branch"]
    master = master
    develop = develop
[branch "develop"]
    remote = origin
    merge = refs/heads/develop
[gitflow "prefix"]
    feature = feature/
    release = release/
    hotfix = hotfix/
    support = support/
    versiontag =
[branch "feature/wxlogin_dev"]
    remote = origin
    merge = refs/heads/feature/wxlogin_dev

branch 节点声明了pull和push时该合并远程的哪个分支

合并分支 切换到需要合并到的分支,比如 master

git merge <需要合并的分支>

例:将 feature/lx 合并到 master

$ git checkout master

$ git merge feature/lx

删除本地分支 $ git branch -D feature/wxlogin_dev

error: Cannot delete the branch ‘feature/wxlogin_dev’ which you are currently on.

当前正在用的分支不能直接删除

注意:一定要先将本地要删除的分支提交到远程服务器备份!!

切换到其他分支即可

$ git checkout master
Switched to branch 'master'
$ git branch
  develop
  feature/wxlogin_dev
* master
$ git branch -D feature/wxlogin_dev
Deleted branch feature/wxlogin_dev (was 5a18d61).
$ git branch
  develop
* master

将本地分支推送到远程服务器 $ git push origin feature/wxlogin_dev:feature/wxlogin_dev


阅读:1459
搜索
  • Linux 高性能网络编程库 Libevent 简介和示例 2332
  • Mac系统编译PHP7【20190929更新】 2208
  • zksync 和 layer2 1899
  • Hadoop 高可用集群搭建 (Hadoop HA) 1891
  • Linux 常用命令 1878
  • 安徽黄山游 1855
  • Windows 安装Swoole 1815
  • 小白鼠问题 1785
  • Hadoop 高可用YARN 配置 1784
  • 使用 Java+Thrift 实现异步事件处理服务 1684
简介
不定期分享软件开发经验,生活经验