close
The Wayback Machine - https://web.archive.org/web/20240822105416/https://www.geeksforgeeks.org/git-fork/
Open In App

Git – Fork

Last Updated : 15 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Forking a repository means creating a copy of the repo. When you fork a repo, you create your own copy of the repo on your GitHub account. When several developers want to work on a project but need to make changes that are inappropriate for the original repository, forking is frequently used in open-source software development.

In this article, we will learn more about Git-Fork and its uses.

What is Git Fork?

In Git, a fork refers to a personal copy of another user’s repository. When you fork a repository, you create an independent copy that exists within your own account or organization. This copy includes all the files, commit history, and branches present in the original repository at the time of forking.

Reasons For Forks 

  • You have your own copy of the project on which you may test your own changes without changing the original project.
  • This helps the maintainer of the project to better check the changes you made to the project and has the power to either accept, reject or suggest something.
  • When you clone an Open-Source project, that isn’t yours, you don’t have the right to push code directly into the project. 

Steps to Forking A Repository 

Step 1: Open the repository that you want to Fork there You can see the icon as shown in the image below in the repo’s top right corner. Now, this feature is used to Fork the repo.

Fork

Git Fork

Step 2: Go to any repository that you want to Fork here we are using a sample repo of Python official repository. 

Python repository

Git Repo

You can see python/cpython. This means python is the maintainer and cpython is the project’s name.  

Step 3: Find the Fork button in the top right corner.

Fork Repo

Fork button

Step 4: Click on Fork. 

Forking the Repo

Forking a repo

Step 5: Now you have your own copy of the repository. But how can we confirm for which do refer to below visual aid as follows:

Copy of Repo

 

Now we can see your user name(**********)/CPython and also below that, we have the link to the original project I forked from. 

Whatever changes are made to ‘******/python? We can make my changes here and then make a Pull Request to the maintainers of the project. Now it is in their hand if they will accept or reject your changes to the main project.

Fork Using Command Line

 Step 1: Open the terminal or gitbash and type the below command.

gh --version 

If it displays the version like in the image below, then the GitHub ClI was already set up on our computer. If not, use this link to set it up. “https://cli.github.com/”

gh --version

GitBash Version

Step 2: You must first log in using the CLI to GitHub using your GitHub account before you may fork the repositories. To do it, issue the following command.

gh auth login --web > SSH

Open the CLI-provided link, then enter your one-time code in the Chrome browser. 

gh auth login

 

Step 3: Once authentication is done. Copy the Repo URL that you to fork into our repo and use the below command.

gh repo fork <REPO URL> --clone
gh repo fork

Fork the repo

— clone is used to get rid of the hurdles in between Fork. That is how we may use the CLI to fork the repository.

Difference between Git Fork vs Git Clone 

Fork

Clone 

To enable independent development without impacting the original repository, a fork is a duplicate of a repository that has been made.

Cloning a repository entails making a local duplicate of an already-existing, remotely hosted Git repository.

When you fork a repository, a new copy of the repository is created under your own account enabling you to experiment and edit as necessary.

A repository is completely duplicated when it is cloned, including all of its files, history, and metadata.

A forking operation produces a fresh, independent copy of the repository that belongs to the forking user and is commonly carried out on a Git hosting service like GitHub or GitLab.

Cloning is commonly carried out via the Git command line on a local system, and it produces an isolated, complete copy of the repository that may be edited and committed locally.

How To Decide Between Git Clone And Fork?

It is advised to utilize “git clone” if you are employed by an organization as a developer and you wish to make contributions to the source code., which is better suited for the “git push and git pull” operations via which other developers can view and validate the code.

Use “git fork” so other developers can’t access or follow your progress if you wish to construct another project in isolation using existing source code as a base.

Configuring Git To Sync Your Fork with the Upstream Repository 

You must carry out the following actions to set up Git to sync your fork with the upstream repository:

Step 1: Clone your fork repository

Clone the repository that you forked to the directory where you want to store the repository by using the following command.

git clone <Repository URL>

Step 2: Add the upstream remote

Know to Add the upstream repository as a remote to your fork repository. By using the following command we can do this.

cd <forkrepo>
git remote add upstream <Repository URL>

Step 3: Fetch the upstream branches

Use the Git fetch command and fetch the branch required from the upstream repository.

git fetch upstream

Step 4: Add the upstream changes to your local branch

Switch the branch you want to update by using the following command.

git checkout main

Know to merge the branches which are fetched from upstream by using the below command.

Git merge upstream/main

Step 5: Push the changes to your fork repository

 With the help of the following command, we can push the changes to your fork repository.

Git Push

Now that your fork repository and the upstream repository are in sync, you can add changes to your fork as necessary.

Conclusion

In this article we covered the differences between a git fork and a git clone, how to set up git to sync your fork with the upstream repository, and how to fork a repository from GitHub using the GUI and CLI using a sample repository and step-by-step instructions with screenshots.



Previous Article
Next Article

Similar Reads

Difference Between Git remote prune, Git prune and Git fetch --prune
Git is a version control system that helps developers manage and track changes in their codebase. Among its many commands, git remote prune, git prune, and git fetch --prune are essential for maintaining a clean and organized repository. This article will explain the differences between these commands, their syntax, uses, and provide examples to il
4 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
3 min read
Git LFS: Managing Large Files in Git Repositories
Git, undoubtedly one of the most popular version control systems, is widely used for managing source code in software development projects. However, one of its limitations is its handling of large files. Traditional Git repositories struggle to efficiently manage large files, leading to bloated repositories and slow performance. This is where Git L
4 min read
Git Subtree vs. Git Submodule
Git Subtree and Git Submodule are both mechanisms in Git that allow you to incorporate external repositories into your own repository. They provide a way to manage dependencies and include code from other projects while keeping your repository organized and maintainable. Git Subtree: Git Subtree allows you to insert a separate repository as a subdi
4 min read
Difference Between Git Fetch and Git Pull
Understanding the difference between git fetch and git pull is important for effective version control in Git. These commands are important for managing your repository and collaborating with team members. In this article, Let us look at Git Fetch and Git Pull separately with the help of an example. What is Git Fetch?The Git Fetch command is used t
4 min read
Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
How to Set Up Git Using Git Config?
Git is a powerful version control system that helps developers manage and track changes in their code. Setting up Git correctly is important for maintaining an organized and efficient workflow. In this article, we'll walk you through the process of setting up Git using the git config command. PrerequisitesBefore we dive into the setup process, make
3 min read
How To Exit Git Log or Git Diff?
When working with Git, the git log and git diff commands are important for viewing commit history and changes between commits, respectively. However, if you're new to Git, you might find yourself stuck in these views, unsure how to exit. This article will guide you through the steps to exit git log or git diff, ensuring a smooth experience while na
2 min read
Git - git prune
Git is a powerful version control system that helps developers manage their code efficiently. However, as your project evolves, you may accumulate unnecessary data that clutters your repository. This is where git prune comes in view. What is git prune?git prune is a Git command that removes objects that are no longer referenced by any branch or tag
5 min read
Difference between “git add -A” and “git add”
When working with Git, the git add command is used to move changes from your working directory to the staging area. However, there are different options and flags that can be used with git add, such as -A, which might lead to some confusion. In this article, we'll explore the differences between git add -A and git add. 1. Git add- CommandThe git ad
2 min read
Git - Difference Between Git Revert, Checkout and Reset
Git offers a range of commands to manage and manipulate your codebase. Among these commands, git revert, git checkout, and git reset are frequently used for different purposes. Understanding the differences between these commands is important for effective version control. In this article, we'll explore the functionalities and use cases of git reve
6 min read
How to Fix Git Error "Unable to create '/path/my_project/.git/index.lock'"?
The Git error "Unable to create '/path/my_project/.git/index.lock'" typically occurs when Git is unable to create or write to the index.lock file. This file is used to prevent simultaneous processes from modifying the repository, which could lead to corruption. Table of Content Remove the Lock File ManuallyUse Git Command to Remove the Lock FileRes
2 min read
Difference Between "git commit" and "git push"?
Git commit and git push are two essential commands you'll use a lot when working with Git. even their frequent use together, they have different functions. In order to help you understand when and how to use these two commands effectively in your version control workflow, this article will break down their differences. What is git commit?git commit
2 min read
How to Fork a GitHub Repository?
GitHub is a great application that helps you manage your Git repositories. Forking a GitHub repository is a common practice that allows you to create your own copy of a repository hosted on GitHub. In this article, we will learn more about Git-Fork and its uses. Table of Content What is GitHub Repository Forking?How to Fork a Repo in GitHubFork Usi
3 min read
Sync Your Fork With Master in GitHub
Forking a repository on GitHub allows you to create your own copy of someone else's project. This is especially useful for contributing to open source projects. However, as the original repository (often referred to as the "upstream" repository) continues to evolve, it's important to keep your fork updated with the latest changes. This article will
3 min read
Difference Between fork and clone in GitHub
Understanding the difference between fork and clone in GitHub is important for anyone looking to collaborate on open-source projects or manage their code efficiently. While both actions involve creating a copy of a repository, their purposes and implementations differ significantly. This article will learn these concepts, making it easier for you t
3 min read
Why Do We Fork On GitHub?
One of the basic functionalities on GitHub is forking: it gives you the ability to create a personal copy of someone else's repository under your GitHub account. After forking, any changes made do not affect the original repository in any way, this particularly helps when you want to take part in open-source projects, experiment with code, or colla
6 min read
Git Features
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it which may b
9 min read
Bare Repositories in Git
Repositories in Git are a snapshot of the folder in which you are working on your project. You can track the progress and changes made to the project by making commits and also revert changes if not satisfactory. Repositories can be divided into two types based on the usage on a server. These are: Non-bare Repositories Bare Repositories What is a N
7 min read
Getting changes from a Git Repository
Git allows performing various operations on the Repositories including the local repositories and remote repositories. The user when downloads a project to work upon, a local repository is created to store a copy of the original project. This local repository stores the changes that are being made by the user. This way, the user can edit the change
4 min read
Git | Working with Stash
Pre-requisites: Git Git allows multiple users to work on the same project simultaneously. Suppose a developer is working on a feature in a branch and he needs to pull changes from some other developer's branch or if he has to work urgently on some other feature, but the feature he is currently working on is incomplete. In this case, you cannot comm
8 min read
Handling repositories with Git remote
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Syncing ability of the git allows the developers to access and work on any project anytime anywhere. The collaboration among developers via git takes place when git provides each individual deve
4 min read
Using Git on CommandLine
Git is very important and powerful tool when it comes to the software development life cycle. Now in this article, we are going to see why git is used vastly in the software industry and what kinds of operations we can perform with git. So git is basically a distributed version control system for tracking changes in source code during software deve
5 min read
Working on BitBucket using Git
Git provides various tools and applications to perform better handling of the work environment. Git is a type of version control system that is used to allow more than one developer to access the source code of a specific application and can modify changes to it that may be seen by other developers. BitBucket is a git-based tool that helps with col
5 min read
Working on Git for GUI
Git has its native environment within the terminal. All the new features are updated first at the command line, and only there is the full power of Git. But plain text isn't the simplest choice for all tasks; sometimes some users are much more comfortable with a point-and-click interface, a visual representation is what they need. Note: There's not
4 min read
Git Rebase
Pre-requisites: Git Git rebase can integrate the changes from one branch to another by overcoming the problems that we might have faced while using the git merge command. The changes we will do will be recorded in the form of logs which are useful to go through if any mistakes happen. What is Branching?Branching means splitting from the master bran
12 min read
Recovering Lost Commits in Git
Git is a very powerful tool, and with great power comes great responsibilities. If not used and handles properly, It might cause you to lose your commits. There might be situations when you may find all of your work missing at once. If you have regularly committed your work, there is a way to recover these lost commits. This tutorial will aim at us
2 min read
Difference Between Git and GitHub
Git: Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. GitHub: GitHub is a web-based G
2 min read
Using Tags in Git
Tagging in GIT refers to creating specific points in the history of your repository/data. It is usually done to mark the release points. Two main purposes of tags are: Make Release point on your code. Create historic restore points. You can create tags when you want to create a release point for a stable version of your code. You can also create ta
2 min read
What is Collaboration in Git?
Pre-requisite: Git &amp; GitHub Collaboration is the way different people can work on the same project together. It is like creating a group in GitHub just like Groups in other social media. The people added to the collaborator's list can be able to push, merge, and do other kinds of similar things on the project. Steps for Collaboration in GIT Ste
5 min read
Article Tags :
three90RightbarBannerImg