How git forking works?

后端 未结 3 1125
遥遥无期
遥遥无期 2021-01-29 09:10

So I am signed in github and I fork a project . Will my forked repo get updated everytime the original repo updates ? Or should I do forking from the original repo everytime so

3条回答
  •  -上瘾入骨i
    2021-01-29 09:24

    A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.

    No your fork won't be updated automatically everytime and you can't fork a repository more than once. If you want, you'll have to delete the prev fork and refork the repo.

    To keep your fork updated with original one you can follow below steps:

    first add the original repo as a remote upstream in your local forked one:

    git remote add upstream [upstream.git]
    

    Now, you can easily syncronize your forked (origin) repository with the upstream one by doing

    git checkout master # Make sure you always run the following commands from the master branch
    git fetch --all
    git pull --rebase upstream master
    git push origin master
    

    This will rebase the upstream changes on your local forked version so the master branch git history will look exactly the same at the end.

    to pull from the original repo use:

    git pull upstream master  # you will get the original repo's update
    

    and to pull from the forked one:

    git pull origin master
    

提交回复
热议问题