Git管理多个远程分支

首先Git不能单独设置pull和push的源,也就是说pull和push的只能保持一致!

背景:
本人的博客是基于hexo-theme-next的,但是因为个人喜好,基于源码做了一写改动。可是官方源码更新了我也要跟着一起更新呀,于是使用git设置不同的源来保持和官方同步更新。

查看本地源

1
> git remote -v

查看远程分支和本地分支的对应关系

1
2
> git branch -vv
* master 77e072b [origin/master] curl新增参数

添加源

1
2
> git clone https://github.com/xmvper/hexo-theme-next.git
> git remote add office https://github.com/theme-next/hexo-theme-next.git

新增分支指向office/master 分支

1
2
3
4
5
6
# 检出office/master分支到本地,并命名hexo-theme-next
> git checkout -b hexo-theme-next office/master

# 或者,先新建分支,然后设置upstream
> git branch hexo-theme-next
> git branch --set-upstream-to=office/master hexo-theme-next 或 git branch -u office/master hexo-theme-next

最后,基于自己的喜好修改文件,再把修改后的内容提交到自己的仓库

1
> git push origin hexo-theme-next