search

Home  >  Q&A  >  body text

git - How to update the code in someone else's repository to the latest version?

I forked someone else's project on Github, then modified it and submitted a PR according to the normal process, and the other party merged it.

Now I need to contribute code to this project, but I found that someone else has updated the new code in the other party's project warehouse. How can I synchronize the code of the forked project in my own warehouse to the same latest version as the other party's warehouse? code and then I contribute?

三叔三叔2753 days ago1263

reply all(5)I'll reply

  • 世界只因有你

    世界只因有你2017-06-20 10:08:00

    First add other people’s repositories to your upstream remote, usually named upstream. Just do it once.

    git remote add upstream  原作者仓库地址

    At this time, use git remote -v to see that one origin belongs to you and the other upstream belongs to the original author.

    Secondly update the code

    Use git fetch upstream to pull the original author’s repository for updates.

    Use git checkout master to switch to your own master

    Use git merge upstream/master, merge or rebase to your master

    reply
    0
  • 为情所困

    为情所困2017-06-20 10:08:00

    If the forked code in your warehouse has not been modified since the last time it was merged, then I recommend directly deleting the project in your warehouse and then forking it again.

    I personally don’t like the merge method mentioned above -- the history record of the merge method is not very nice.

    If you don’t want to delete and re-fork, you can directly:

    git checkout master
    git remote add upstream 别人的代码库地址
    git fetch upstream/master
    git reset --hard upstream/master

    reply
    0
  • 怪我咯

    怪我咯2017-06-20 10:08:00

    First add the address of the library you forked

    git remote add FORK-sync https://github.com/xxx/yyy.git
    git remote -v

    You can see similar ones

    FORK-sync    https://github.com/xxx/yyy.git (fetch)
    FORK-sync    https://github.com/xxx/yyy.git (push)
    origin    git@github.xxx/born-1.git (fetch)
    origin    git@github.xxx/born-1.git (push)

    Then accept the contents of the forked library

    git fetch FORK-sync

    Merge

    git merge FORK-sync/master

    Just push it to your remote warehouse

    git push

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-20 10:08:00

    cd YOUR-FORKED-REPO
    git fetch upstream
    git checkout master
    git merge upstream/master

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-20 10:08:00

    These graphic tutorials have been available for a long time. http://blog.csdn.net/qq133247...

    reply
    0
  • Cancelreply