In Git, forking a repository means making a copy of a repository, stored either publicly or privately, under your personal account on a remote hosting service, such as GitHub.
For example, if you were to fork the VS Code GitHub repository, the new copy would be stored at
Forking a repository means you can make any changes you want to the code without affecting the original project. You can choose to share those changes with the original repo through the pull request process.
The new forked copy is still connected to the original repository and is considered ‘downstream’ from the original ‘upstream’ repository. Any changes made to the original upstream repository can be easily applied to the downstream repository if desired.
This connection allows downstream copies to suggest changes to the upstream repository through use of GitHub pull requests. For example, if you want to fix a bug found in a repository, you would fork the repository, fix the issue on your copy, and then start a pull request to ask the upstream repository owner to merge your proposed changes into the original repository.
Sometimes a repository is forked to act as a starting point for your own idea, commonly done in the world of open source software.
GitKraken’s robust integration with GitHub makes it swift and simple to clone, fork, add remotes, and manage pull requests. Plus, developers can get the best of both a GUI and CLI.
How to Fork in GitHub with the GitKraken CLI
To fork a repository in GitHub using the Git CLI:
First, navigate to the Git repository you want to fork on GitHub.com.
Once there, click the Fork button in the upper right hand side of the repository’s GitHub page.
Congrats! Now you have a copy of the repository in your GitHub account.
Working with a Forked Repository in GitHub
Now that the fork exists, you will want to make sure your local copy of the repository can access both the original and the forked repo.
First, perform a Git clone of the original repository to your local machine using the Git CLI and SSH by typing:
git clone email@example.com:Axosoft/vscode-gitlens.git
This step will set the original repository as the
origin Git remote.
Now, add your forked GitHub repository as a new Git remote locally by typing:
git remote add GitHub-user-name firstname.lastname@example.org:GitHub-user-name/vscode-gitlens.git
Remember to replace
GitHub-user-name with your actual GitHub user account name in both places.
You are now set up with a local repository with two connected remotes, the original repo and your fork on GitHub.
Pulling from a Forked GitHub Repository
If you want to pull changes from your forked GitHub repository, type:
git pull GitHub-user-name <branch-name>
If you want to fetch and merge changes in from the original repository, type:
git pull origin <branch-name>
Pushing to a Forked GitHub Repository
You can now push changes to your forked GitHub repository by typing:
git push GitHub-user-name <branch-name>
If allowed access, you can push changes directly to the original repository by typing:
git push origin <branch-name>
The process of adding and managing forked GitHub repositories is easy and intuitive with GitKraken, so you can get set-up and contributing to your project quickly. We know your time is valuable.
How to Fork in GitHub with the GitKraken Git Client
If you want to fork in GitHub using the GitKraken Git Client, you will first clone the repo you wish to fork.
To begin the process of cloning a GitHub repo, navigate to Repository Management → Clone. You have the ability to clone using a GitHub URL and can select where on your local machine you want to clone to.
After you have successfully cloned the GitHub repository, you can see the repo from the remote panel to the left of the commit graph in GitKraken’s central UI.
Next, right-click on the remote and select Fork and Add Remote from the context menu.
That’s all it takes! To verify that you have successfully forked the GitHub repository, you can check to see a new local fork visible below the original remote in the left panel.
GitHub Clone vs Fork
While forking and cloning a GitHub repository both do make a copy of the original repository, it’s important to note the key differences in these concepts. Cloning a repository creates a local copy of the repo and automatically sets a Git remote to that repository on GitHub. If the project is owned by someone else, you won’t be able to push any changes back to that original repository.
Forking a GitHub repository, on the other hand, creates an online copy of the repository that you own, which can be used as a remote. You can push and pull to this repository as needed, and you can pull in changes from the original repo that you forked, in addition to your copy.
GitHub Fork vs Branch
In the simplest terms, a fork is a way to make a copy of a whole repository at once, while a branch is a way to work within a repository.
A Git branch is a way to safely make a new set of commits within the same copy of a project, without making changes to the main branch until you’re ready. A branch is, in all reality, just a new pointer to a commit that moves along with each new commit you make, and only diverges in the graph if a commit is made on a common ancestor commit.
A fork can contain many branches, and you can update each branch from the upstream just as you would the main branch. It is common practice to put new work in a feature branch and create a pull request from that branch when attempting to update the original upstream repository.
How to Unfork a GitHub Repository
Unforking in GitHub is not a common operation and requires the direct assistance of the GitHub support team. You will need to visit the GitHub Support Request page and select the “Attach, detach or reroute forks” option. The virtual assistant will guide you through the rest of the process.
If you’re ready to make the process of forking GitHub repositories easier and faster with more visibility and control, download the GitKraken Git Client, now with GUI and CLI, free today.