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
|
在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>
|
两种语法作用完全相同。
原文:http://www.cnblogs.com/NTsWatch/p/7352893.html