Git 分支

2017-11-22  本文已影响0人  JoinPerson

创建分支

git branch <local-branch-name>

git checkout -b <local-branch-name> 创建一个分支并切换到创建的分支上

查看各个分支当前所指的对象

git log --oneline --decorate --graph --all

切换分支

git checkout <local-branch-name>

合并分支

git merge <branch-name>

删除分支

git branch -d <branch-name>

git branch -D <branch-name>

git branch -r -d <branch-name>        删除远程跟踪分支

查看分支

git branch        查看本地分支

git branch -a        查看本地和远程跟踪分支

git branch -v         查看每个分支最后一次提交

git branch --merged        查看已经合并到当前分支的分支

git branch --no-merged        查看未合并到当前分支的分支

获取远程分支的更多信息

git ls-remote <remote-name> 显式地获得远程引用的完整列表

git remote show <remote-name>  获得远程分支的更多信息

在克隆某个项目时改变远程仓库名(不用默认的远程仓库名)

git clone <url> -o <remote-name>

抓取远程仓库数据

git fetch [remote-name]

推送分支到远程分支上

git push [remote-name] [local-branch-name] : [remote-branch-name]

创建一个同名的跟踪分支

git checkout --track  [remote-name/remote-branch-name]

基于跟踪分支创建一个本地分支

git checkout -b [local-branch-name]  [remote-name/remote-branch-name]

设置已有的本地分支跟踪一个刚刚拉取下来的远程分支,或者想要修改正在跟踪的上游分支

git branch -u [local-branch-name] [remote-name/remote-branch-name]

git branch --set-upstream-to [local-branch-name] [remote-name/remote-branch-name]

合并一个已经跟踪的分支

git merge @{u}

git merge @{upstream}

查看设置的所有跟踪分支

git branch -vv

抓取所有的远程仓库的数据

git fetch --all

抓取数据而且合并

git pull

删除远程分支

git branch <remote-name> --delete <remote-branch-name>

变基

不要对在你的仓库外有副本的分支执行变基

git rebase [local-branch-name]

git rebase <basebranch> <topicbranch]

git rebase --onto <basebranch> <server> <client> 取出client分支,找出处于client分支和server分支的共同祖先之后的修改,然后把它们在master分支上重放一遍

更多变基操作

上一篇下一篇

猜你喜欢

热点阅读