git - How to keep the Fork project consistent with the source
淡淡烟草味
淡淡烟草味 2017-05-02 09:39:14
0
2
740

The background is like this. I forked a copy from someone else's warehouse to my own, then created a new branch in my own warehouse and worked on it.
Now that the trunk of someone else's warehouse has been updated, I need to update it locally and submit it. Go to your own warehouse
and read the method on the Internet, which says to use git remote add name location
and then git pull name master
and then push Go to your own warehouse
But it happens like this when I push. Xiaobai, please ask

淡淡烟草味
淡淡烟草味

reply all(2)
淡淡烟草味

If you want to update the master branch of your fork, you should git checkout master, 然后再pull。这样pull之后就可以push 到 origin master do it first.

If you just want to update your current wuninghan.banbranch:

  1. If your current modification has not been committed yet, then first git stash。如果已经commit 过,就接着进行下一步。这时候可以用git statuscheck whether there is code in the Staging Area.

  2. This step can be done in many ways. My habit is to start git fetch --all,然后git rebase ruoxue/master。当然,你也可以直接git pull --rebase first, for the same reason.

  3. If you stash in the first step, then this time git stash apply stash@{0} (Theoretically it is 0, if you stash once above)

If there are conflicts in the second step, just deal with them.

PHPzhong

Take vuejs-templates/webpack as an example, because I am forking this vue project template to make changes

Secondly, I think this project has its own special characteristics. Its main branch does not use the files under the master,而是dist,而加载模板的工具vue-cli默认会下载dist branch as the project template.

This is the following situation

  • For convenience, it is better to make changes directly on dist, so that using vue-cli can save a few words

  • The changes made to dist上进行改动,实际是出于自己的需求,并不希望提交proriginal repo,同时又希望能有一个分支用于保持跟original repo一致,且同时用于提交pr are actually out of my own needs. I don’t want to submit pr to original repo, but I also hope to have a branch for maintenance. It is consistent with original repo, and is also used to submit pr

I will create a new track-1 branch based on the dist分支的基础上新建一个track-1 branch after the fork
The specific steps are as follows

# 创建track-1分支
git checkout -b track-1 dist

# 添加origin repo remote
git remote add original https://github.com/vuejs-templates/webpack.git

# ....这里是开发时间...
# 1.对dist做自己的改动,同时origin repo有更新,希望保持更新

# 把original所有数据拉下来
git fetch original

# 切回track-1分支
git checkout track-1

# 把original主分支rebase到track-1分支
git rebase original/dist

# 切换回fork的dist分支
git checkout dist

# 合并track-1分支的更新
# 这里没用rebase而是用merge,因为感觉这个用rebase比较繁琐,实际上应该用哪个我也不清楚
git merge track-1

# ...解决冲突等等...
# git push

# ....这里是开发时间...
# 2.对track-1做改动,希望提交pr给original repo

# 把改动提交,提交前需要确认分支为最新状态
# git fetch original
# git rebase original/dist
git push

# ...接下来就是上github进行操作...

# 假如已合并pr的话,在切回dist分支
git checkout dist
git merge track-1

It still seems a bit cumbersome, I don’t know if this process is reasonable

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template