How to fork a repository in Git

Forking creates a personal copy of a repository under your account, enabling contributions to open-source projects without direct write access to the original repository. As the creator of CoreUI, a widely used open-source UI library, I’ve worked with forked repositories in collaborative development throughout my 25 years of development experience. The most common approach is using GitHub’s fork button to create the copy, then cloning it locally for development. This method establishes the foundation for pull request workflows and collaborative open-source contributions.

Fork repository via GitHub interface, clone your fork, and configure upstream remote.

# Fork the repository via GitHub web interface first
# Then clone your fork locally
git clone https://github.com/your-username/repo-name.git
cd repo-name

# Add the original repository as upstream remote
git remote add upstream https://github.com/original-owner/repo-name.git

# Verify remotes
git remote -v
# origin    https://github.com/your-username/repo-name.git (fetch)
# origin    https://github.com/your-username/repo-name.git (push)
# upstream  https://github.com/original-owner/repo-name.git (fetch)
# upstream  https://github.com/original-owner/repo-name.git (push)

# Keep your fork updated with upstream changes
git fetch upstream
git checkout main
git merge upstream/main
git push origin main

Here the fork creates a complete copy of the repository under your GitHub account. Cloning your fork downloads it to your local machine for development. Adding upstream remote links to the original repository, enabling you to pull updates. The fetch upstream command retrieves changes from the original repository. Merging upstream/main incorporates those changes into your local branch. Pushing to origin updates your fork with the latest upstream changes.

Best Practice Note:

This is the forking workflow we recommend for CoreUI contributors wanting to submit pull requests and improvements. Create feature branches from an updated main branch to avoid conflicts, regularly sync with upstream to prevent your fork from becoming outdated, and never commit directly to main—always use feature branches for pull requests to maintain clean history.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to disable a button in JavaScript
How to disable a button in JavaScript

How to loop through a 2D array in JavaScript
How to loop through a 2D array in JavaScript

How to sort an array of objects by string property value in JavaScript
How to sort an array of objects by string property value in JavaScript

How to Open Link in a New Tab in HTML?
How to Open Link in a New Tab in HTML?

Answers by CoreUI Core Team