Use GIT fork / branches

狂风中的少年 提交于 2019-12-01 00:22:09
VonC

No fork: fork is cloning that repo on BitBucket to get your own (on BitBucket): it is a clone on the server side.
See, for illustrations:

You need a fork only when you cannot push directly to the upstream repo: you push to your fork, and make a pull request to the upstream repo.
This is not the case here.

Just branch and push your branch to the one and only BitBucket repo you need (to which you have write access).

Whenever you have modifications you need to publish both on master and on your branch,

x--x--x                  (master => origin/master)
       \ 
        y--y--c--y--c--y (yourBranch  => origin/yourBranch)
  • reorder said branch (rebase interactive) for the common commits to appear first,
x--x--x                  (master => origin/master)
       \ 
        c--c--y--y--y--y (yourBranch  => origin/yourBranch)
  • git pull master (in order to make sure master on your local clone reflects the latest commits published by other on BitBucket)
x--x--x--x--x            (master => origin/master)
       \ 
        c--c--y--y--y--y (yourBranch  => origin/yourBranch)
  • rebase your branch on top of master and test if everything still compile and pass the tests
x--x--x--x--x                  (master => origin/master)
             \ 
              c--c1-y--y--y--y (yourBranch  => origin/yourBranch)
  • merge the new common commits from your branch to master:
    git checkout master; git merge c1
x--x--x--x--x--c--c1                 (master => origin/master)
                   \ 
                    y--y--y--y (yourBranch  => origin/yourBranch)
  • git push master (since you have pulled master before pushing: your local master was up-to-date relative to BitBucket 'origin' master. Your push is a trivial merge on the BitBucket side: you are only introducing new commits)

  • git checkout yourBranch && git push -f origin yourBranch
    Since you have rebased yourBranch, you have rewritten its history, you need to forced push to BitBucket side.
    But since it is your branch, it is ok (nobody else would have pulled from it, and would need to reset it in order to take into account your new history).


Note that another way avoiding the rebase --interactive step to reorder your common commits would be to cherry-pick them directly from yourBranch to master.
But I dislike cherry-picking, in that it:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!