Use of Fork in Git

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:

image-20221205230013156

Then you can see the following structure in Zhang San's account:

image-20221205230955686

Use Zhang San's account to click to enter the xlog project, as follows:

image-20221205231400596

Click Fork in the upper right corner, as follows:

image-20221205231605196

Core points:

  1. Choose a namespace, usually choose your own GitLab name
  2. Select the visibility level, the default is private
  3. Enter the project name, usually the default

Finally click Fork Project to complete the Fork, as shown below:

image-20221205231912499

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:

Gitlab CE installation

Git command booklet

reference:

https://blog.csdn.net/weixin_43517190/article/details/125159723

https://blog.csdn.net/u013673437/article/details/127198924

Guess you like

Origin blog.csdn.net/qusikao/article/details/128297273