Fork in GitLab or GitHub can be understood as a physical copy, a means of managing code.
When participating in the code contribution of an open source project, you usually do not directly obtain the Developer permission of the source code warehouse. This is different from general company development. Companies generally set whether there is Push permission on the branch. Use Fork to physically copy the code and develop it under your own NameSpaces. During development, you can make any changes, deletes, commits or pushes to the branch. The process is exactly like developing your own code.
What is Fork
Fork in GitLab or GitHub can be understood as a physical copy, a means of managing code.
When participating in the code contribution of an open source project, you usually do not directly obtain the Developer permission of the source code warehouse. This is different from general company development. Companies generally set whether there is Push permission on the branch. Use Fork to physically copy the code and develop it under your own NameSpaces. During development, you can make any changes, deletes, commits or pushes to the branch. The process is exactly like developing your own code.
How to Fork
Take GitLab as an example. First, use Zhang San to create a project named xlog, the project permission is Owner, and set Li Si's permission as Reporter. as follows:
Then you can see the following structure in Zhang San's account:
Use Zhang San's account to click to enter the xlog project, as follows:
Click Fork in the upper right corner, as follows:
Core points:
- Choose a namespace, usually choose your own GitLab name
- Select the visibility level, the default is private
- Enter the project name, usually the default
Finally click Fork Project to complete the Fork, as shown below:
Update the remote warehouse to the Fork warehouse
On the GitLab or GitHub platform, after developer Zhang San forks and develops Li Si's project, if Li Si continues to submit the project later, how does Zhang San get updates in the fork's code?
1. Configure the remote warehouse location for the Fork library, first check the status of the remote warehouse:
$ git remote -v
origin http://lisi:[email protected]/lisi/xlog.git (fetch)
origin http://lisi:[email protected]/lisi/xlog.git (push)
2. Add the remote upstream address for the Fork library:
$ git remote add upstream http://192.168.109.112/zhangsan/xlog.git
3. Use git remote -v to check whether the configuration is successful:
$ git remote -v
origin http://lisi:[email protected]/lisi/xlog.git (fetch)
origin http://lisi:[email protected]/lisi/xlog.git (push)
upstream http://192.168.109.115/zhangsan/xlog.git (fetch)
upstream http://192.168.109.115/zhangsan/xlog.git (push)
4. Capture remote upstream
$ git fetch upstream
5. Check the upstream log, as shown in the following command and legend:
$ git log --all --graph --oneline
* 71d3aa7 (upstream/main) 测试Fork
* 9ca3f3b (HEAD -> main, origin/main, origin/HEAD) no message
6. Merge the code on the remote upstream to Fork
git merge upstream/main
7. Submit the code of the local Fork
git push origin main
recommend:
reference:
https://blog.csdn.net/weixin_43517190/article/details/125159723
https://blog.csdn.net/u013673437/article/details/127198924