Github 学习笔记

Git分支管理技巧
本文介绍如何使用Git进行分支管理,包括创建、查看、推送及删除本地和远程分支的方法。此外,还介绍了如何解决推送过程中遇到的问题。

命令: 命令manual

git branch --all 用来查看所有分支(包括远程关联库的分支)

chenruideMacBook-Pro:tt chenrui$ git branch --all

  dev

* master

  remotes/tt2/master

  remotes/tt2/ss

  remotes/tt2/yy

git remote -v 查看所有跟本地库关联的远程库分支情况

git remote add <本地库给远程库起的的别名> <远程库的URL>

git branch uu 新建一个本地分支,名字叫uu

chenruideMacBook-Pro:tt chenrui$ git branch

  dev

* master

chenruideMacBook-Pro:tt chenrui$ git branch uu

chenruideMacBook-Pro:tt chenrui$ git branch

  dev

* master

  uu

 

名字是uu的分支是可一个向别的非同名的远程分支推送的,前提是uu已经和别的分支建立关联

建立本地分支uu时可以用

chenruideMacBook-Pro:tt chenrui$ git branch ooo tt2/master

Branch ooo set up to track remote branch master from tt2.

这样uu就可以推送到远程tt2库的master分支

而且推送时

chenruideMacBook-Pro:tt chenrui$ git push

fatal: The upstream branch of your current branch does not match

the name of your current branch.  To push to the upstream branch

on the remote, use

 

    git push tt2 HEAD:master

 

To push to the branch of the same name on the remote, use

 

    git push tt2 ooo

 

如果push后面写HEAD:master (不写HEAD什么也不发生) ,就直接把uu当成master推送到远程master .如果写上ooo 就会在远程库内新建一个叫ooo的分支

 

 

查看远程分支

加上-a参数可以查看远程分支,远程分支会用红色表示出来(如果你开了颜色支持的话):

1
2
3
4
5
6
7
8
9
10
$ git branch -a
master
remote
tungway
v1.52
* zrong
remotes/origin/master
remotes/origin/tungway
remotes/origin/v1.52
remotes/origin/zrong

删除远程分支和tag

在Git v1.7.0 之后,可以使用这种语法删除远程分支:

1
$ git push origin --delete <branchName>

删除tag这么用:

1
git push origin --delete tag <tagname>

否则,可以使用这种语法,推送一个空分支到远程分支,其实就相当于删除远程分支:

1
git push origin :<branchName>

这是删除tag的方法,推送一个空tag到远程tag:

1
2
git tag -d <tagname>
git push origin :refs/tags/<tagname>

两种语法作用完全相同。

 

转载于:https://www.cnblogs.com/NTsWatch/p/7352893.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值