举例说明
先定义一下
本地分支名: local_branch
远程分支名: remote_branch
克隆远程分支到本地
git clone [email protected]:mayouchen-release/weixin-platform-frontend.git
查看本地分支
git branch
查看远程和本地分支
git branch -a
切换远程和本地分支
git checkout develop //develop为分支名
创建本地分支 local_branch
git branch local_branch
删除本地分支local_branch
git branch -d local_branch
删除远程分支remote_branch
方法一:
git push origin :remote_branch
方法二:
git branch -d | -D branchname 删除branchname分支
方法三:
git branch -d -r branchname 删除远程branchname分支
远程分支 oldbranch 重新命名成 newbranch
git branch -m | -M oldbranch newbranch 重命名分支,
如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
推送本地分支 local_branch 到远程分支 remote_branch 并建立关联关系 (重点)
远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch
远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch