-
Create a new branch set up to track the relationship between time
git checkout -b new_branch_name [--track] origin/remote_branch_name
--track option can be omitted
-
Has been set up to track the relationship between branch and remote branch
git branch -u origin/remote_branch_name local_branch_name
Note: -u option --set upstream-to-shorthand, so the above command can be written as
git branch --set-upstream-to=origin/remote_branch_name local_branch_name
local_branch_name may be omitted, the default value is the current branch
Get Remote branch information
-
Pull a remote repository branch information
git fetch origin
-
View all branches (local and remote)
git branch -a
-
The default switch remote branch
git remote set-head origin remote_branch_name
-
Local establish remote branch
git push origin local_branch_name:remote_branch_name
i.e., the new remote branch remote_branch_name
-
Local delete remote branch
git push origin --delete remote_branch_name
rebase workflow
-
And merge the difference
Two branches of a local branch of my master mywork a main branch
Now I modified parts to be incorporated into the master, you can have two options merge or rebase
Final result of both is the same, but the difference is you rebase a two branch on a branch, before mywork merge all patch is commit disappeared
The merge is still two branches, but this intersection point after merge
-
How to rebase
First native code library is not up to date, so start with the distal end of the warehouse pull it
git checkout master`
git pull然后 开始切换到mywork分支开始rebase
git checkout mywork
git rebase master这个时候就开始rebase 了,一般情况下rebase都是会有冲突的,详细查看冲突可以用命令
git status
然后就会显示哪个文件有冲突,然后打开有冲突的哪个文件,会发现有一些“<<<<<<<”, “=======”, “>>>>>>>” 这样的符号。原来的更改是master分支上的更改,传入的更改是工作分支mywork分支上的更改;
“<<<<<<<” 表示冲突代码开始
“=======” 表示mywork与master冲突代码分隔符
“>>>>>>>" 表示冲突代码的结束
<<<<<<<
所以这一块区域mywork的代码
=======
这一块区域master的代码
>>>>>>>rebase 和 merge的另一个区别是rebase 的冲突是一个一个解决,如果有十个冲突,先解决第一个,然后用命令
git add -u
git rebase --continue继续后才会出现第二个冲突,直到所有冲突解决完,而merge 是所有的冲突都会显示出来。 另外如果rebase过程中,你想中途退出,恢复rebase前的代码则可以用命令
git rebase --abort
所以rebase的工作流就是
git rebase
while(存在冲突) {
git status
找到当前冲突文件,编辑解决冲突
git add -u
git rebase --continue
if( git rebase --abort )
break;
}最后冲突全部解决,rebase成功!!
然后我需要把本地的mywork 分支push 到远端mywork分支上然后再给远端的master分支 PR。
总结
-
rebase工作流:
git rebase
while(存在冲突) {
git status
找到当前冲突文件,编辑解决冲突
git add -u
git rebase --continue
if( git rebase --abort )
break;
} -
git pull (或fetch && merge)
编辑冲突文件
git push