Are Git forks actually Git clones?

前端 未结 10 1125
攒了一身酷
攒了一身酷 2020-11-22 04:17

I keep hearing people say they\'re forking code in Git. Git \"fork\" sounds suspiciously like Git \"clone\" plus some (meaningless) psychological willingness to forgo future

10条回答
  •  渐次进展
    2020-11-22 04:47

    I keep hearing people say they're forking code in git. Git "fork" sounds suspiciously like git "clone" plus some (meaningless) psychological willingness to forgo future merges. There is no fork command in git, right?

    "Forking" is a concept, not a command specifically supported by any version control system.

    The simplest kind of forking is synonymous with branching. Every time you create a branch, regardless of your VCS, you've "forked". These forks are usually pretty easy to merge back together.

    The kind of fork you're talking about, where a separate party takes a complete copy of the code and walks away, necessarily happens outside the VCS in a centralized system like Subversion. A distributed VCS like Git has much better support for forking the entire codebase and effectively starting a new project.

    Git (not GitHub) natively supports "forking" an entire repo (ie, cloning it) in a couple of ways:

    • when you clone, a remote called origin is created for you
    • by default all the branches in the clone will track their origin equivalents
    • fetching and merging changes from the original project you forked from is trivially easy

    Git makes contributing changes back to the source of the fork as simple as asking someone from the original project to pull from you, or requesting write access to push changes back yourself. This is the part that GitHub makes easier, and standardizes.

    Any angst over Github extending git in this direction? Or any rumors of git absorbing the functionality?

    There is no angst because your assumption is wrong. GitHub "extends" the forking functionality of Git with a nice GUI and a standardized way of issuing pull requests, but it doesn't add the functionality to Git. The concept of full-repo-forking is baked right into distributed version control at a fundamental level. You could abandon GitHub at any point and still continue to push/pull projects you've "forked".

提交回复
热议问题