在使用 git 进行分支开发与合并的时候需要用到这些命令。其他基本 git 命令参考 Git 简易食用指南
git branch
查看分支
git branch
查看当前分支情况
![](https://upload-images.jianshu.io/upload_images/12904618-1317c08d2fb90368.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/362/format/webp)
创建分支
git branch 分支名
创建一个新的分支
切换分支
git checkout 分支名
切换到该分支
分支提交到线上
git add . git commit -m "xxx" git remote add origin github项目地址 //如果出现remote origin already exists git remote rm origin git remote add origin github项目地址 git push origin index-swiper //(index-swiper 为branch 分支名)
![](https://upload-images.jianshu.io/upload_images/12904618-3f27568a91edb8d8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/641/format/webp)
合并到 master
git checkout master //切换到 master git merge origin/index-swiper //选择要合并到 master 的分支 git push origin master //push 即可
![](https://upload-images.jianshu.io/upload_images/12904618-42056469c9cab105.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/642/format/webp)