git 命令

新建分支

1  // 新建本地分支并切换到新分支
2 git checkout -b dbg_lichen_star
3 // 推送新分支到远程
4 git push origin dbg_lichen_star:dbg_lichen_star
5 // 删除远程分支
6 // 方法一
7 git push origin :dbg_lichen_star
8 // 方法二
9 git push origin --delete dbg_lichen_star

修改分支

1 git branch -m old_branch new_branch # Rename branch locally 
2 git push origin :old_branch # Delete the old branch 
3 git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote

pull拉取特定分支代码

1、将远程指定分支 拉取到 本地指定分支上:

git pull origin <远程分支名>:<本地分支名>

2、将远程指定分支 拉取到 本地当前分支上:

git pull origin <远程分支名>

3、将与本地当前分支同名的远程分支 拉取到 本地当前分支上(需先关联远程分支)

git pull origin

在克隆远程项目的时候,本地分支会自动与远程仓库建立追踪关系,可以使用默认的origin来替代远程仓库名,
所以,我常用的命令就是 git pull origin <远程仓库名>,操作简单,安全可控。

push操作

1、将本地当前分支 推送到 远程指定分支上(注意:pull是远程在前本地在后,push相反):

git push origin <本地分支名>:<远程分支名>

2、将本地当前分支 推送到 与本地当前分支同名的远程分支上(注意:pull是远程在前本地在后,push相反):

git push origin <本地分支名>

3、将本地当前分支 推送到 与本地当前分支同名的远程分支上(需先关联远程分支)

git push origin

同样的,推荐使用第2种方式,git push origin <远程同名分支名>

附:

// 将本地分支与远程同名分支相关联

git push --set-upstream origin <本地分支名>

参考文档 https://blog.csdn.net/u010059669/article/details/82670484

原文地址:https://www.cnblogs.com/1032473245jing/p/11376238.html