Git Fork Meaning
There is no git fork command. From the command line you can clone a Git repo, you can pull from a Git repo and you can fetch updates from a Git repo, but there is no git fork command if you’re working with a standard Git installation.
Git fork definition
A fork in Git is simply a copy of an existing repository in which the new owner disconnects the codebase from previous committers. A fork often occurs when a developer becomes dissatisfied or disillusioned with the direction of a project and wants to detach their work from that of the original project. When a git fork occurs, previous contributors will not be able to commit code to the new repository without the owner giving them access to the forked repo, either by providing developers the publicly accessible Git URL, or by providing explicit access through user permission in tools like GitHub or GitLab.
How to fork Git or GitHub repos
This may come as a surprise, but there is no explicit Git command that creates a fork.
If you have a Git repository on your personal computer, you can create a fork simply by copying the Git repo to a new folder and then removing any remote references in the Git config file. That will create a isolated and independent Git fork that will no longer synchronize with the original codebase. It’s really that simple.
|Your intro to GitHub Actions training course|
Here’s how to get started with GitHub Actions:
Follow these tutorials and you’ll learn GitHub Actions fast.
If you need to fork a GitHub or GitLab repo, it’s as simple as navigating to the landing page of the repository in your web browser and clicking on the Fork button on the repository’s home page. A forked copy of that Git repository will be added to your personal GitHub or GitLab repo. That’s it. That’s all you have to do to fork a Git repo.
Command line Git forks
Git lends itself to the command line.
While not every developer loves the command prompt or the Bourne Again Shell (BASH), anyone doing version control becomes quickly adept at issuing a git reset or a git commit in the terminal window. However, vendors like GitHub and GitLab do offer supplemental Git features that aren’t available through the command line. GitHub’s fork feature is one of them, along with the ability to perform a pull request.
You simply can’t do a GitHub fork from the command line with only a basic Git installation. To perform such version control hijinks, a user must download and install the GitHub command-line interface (CLI) tools.
How to fork GitHub on the command line
To perform a command-line GitHub fork, follow these steps:
- Download and install the GitHub CLI tools.
- Open a terminal window and log in with the gh CLI command.
- Find the GitHub URL of the repo you wish to clone.
- Use the gh CLI tool to perform a command-line GitHub fork of repository of interest.
The CLI syntax to log into GitHub through the terminal window is as follows:
gh auth login --web
The –web switch will trigger a browser-based authentication. Simply log into your GitHub account and provide the authentication code displayed in the terminal window. This will allow you to then issue subsequent, authenticated, GitHub commands.
GitHub fork command
Once authenticated, issue the following GitHub fork command. Note that the –clone option is added to force the remote repository to be cloned locally.
gh repo fork https://github.com/learn-devops-fast/spock-lizard-docker.git --clone
Once you issue this command, your cloud-hosted GitHub account will include a fork of the original repository, and a clone will be made on the local file system. From there, you can issue a Git commit, push, fork and even GitHub pull requests just as they would with any ordinary Git or GitHub repository.
And that’s how easy it is to fork a GitHub repo from the command line.