目录
git创建分支并推送到远程分支
新建一个本地分支.
git checkout -b show_branch_local
查看当前分支状态
git branch
结果:
master
on_cluster_snapshot_etl_v2
* show_branch_local
remotes/origin/HEAD -> origin/master
remotes/origin/master
星号(*)表示当前所在分支。没有前面的字母的是本地分支。现在的状态是成功创建的新的分支并且已经切换到新分支上。
把新建的本地分支push到远程服务器,远程分支与本地分支同名(当然可以随意起名):
git push origin show_branch_local:show_branch_remotes
结果提示:
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for show_branch_remotes, visit:
remote: https://git.xxxx.com.cn/snapshot-fe/snapshot_etl_v2/merge_requests/new?merge_request%5Bsource_branch%5D=show_branch_remotes
remote:
To https://git.xxxx.com.cn/snapshot-fe/snapshot_etl_v2.git
* [new branch] show_branch_local -> show_branch_remotes
zwdeMacBook-Pro:snapshot_etl_v2 zhaowang$
使用查看分支命令查看,remotes后面是否有自己刚推到远程的分支命令
git branch -a
结果:
master
on_cluster_snapshot_etl_v2
* show_branch_local
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/on_cluster_snapshot_etl_v2
remotes/origin/show_branch_remotes
将本地分支与远程分支关联
git branch --set-upstream 本地分支名 origin/远程分支名
注意上面set 前有两个连续的- 且和up之间的-没有空格。如
$ git branch --set-upstream nspagev_rank_v2_with_data_test1 origin/nspagev_rank_v2_with_data_test1
删除指定远程分支
git push origin –delete show_branch_remotes
或者推送一个空分支到远程分支(就相当于删除了远程分支)
git push origin :show_branch_remotes
结果提示:
To https://git.xxx.com.cn/snapshot-fe/snapshot_etl_v2.git
- [deleted] show_branch_remotes
查看分支命令,已经看不到show_branch_remotes了,即已经删除。
删除远程分支的某个指定文件
1)预览将要删除的文件(当前分支下)
git rm -r -n –cached 目标文件/文件夹名称
加上 -n 这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
上面的目标文件可以不写路径,结果会提示到带着具体的路径。
2) 确定无误后再删除文件
git rm -r --cached 文件/文件夹名称
如$ git rm -r --cached get_days_data_auto_0803_31.sh get_days_data_auto_0903_31.sh
结果提示
rm 'script/get_days_data_auto_0803_31.sh'
rm 'script/get_days_data_auto_0903_31.sh'
3) 提交说明与推送。
git commit -m '删除之前写死的脚本
git push 本地分支名:远程分支名
(注意此要加origin,然后空格如)
git push origin on_cluster_snapshot:on_cluster_snapshot
参考: git创建分支并推送到远程分支_git新建分支并推送到远程_赖进杰的博客-CSDN博客
https://www.jianshu.com/p/de75a9e3d1e1