Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly fork a local git repository?

Tags:

git

git-fork

I have a local git repo. I want to fork it and use it as the basis of a new project. The new project should never be able to push anything back to the original project. Here is what I think I should do...

git clone originalproject newproject
git remote remove origin

Is there anything else I ought to do to break the link between the two repos and create an independent local fork?

edit: This will work fine locally but if you'd rather link to a new remote repo then see codeWarrior's answer below.

like image 366
Roger Heathcote Avatar asked Sep 26 '19 09:09

Roger Heathcote


People also ask

How do I Fork a repository in GitHub?

In the top-right corner of the page, click Fork . To learn more about GitHub CLI, see " About GitHub CLI ." To create a fork of a repository, use the gh repo fork subcommand. To create the fork in an organization, use the --org flag.

How does forking (Git Fork) work?

How does Forking (Git Fork) work? Git Fork is a simple process in GitHub and it does not require to use any git command. The process of Git Fork follows the below steps: Fork a Repository: User creates a copy of the repository to their own GitHub account, the steps for the same are covered in the next section.

How do I make changes to a GitHub repository?

Fork the repository Using the appropriate repository, create a fork of the repository into your own GitHub account by using the GitHub website. A personal fork is required since all main documentation repositories provide read-only access. To make changes, you must submit a pull requestfrom your fork into the main repository.

How do I choose a folder path for a git repository?

Choose a folder name should be easy for you to remember and type. For example, consider a root folder C:\docs\or make a folder in your user profile directory ~/Documents/docs/ Important Avoid choosing a local folder path that is nested inside of another git repository folder location.


1 Answers

Yep, it will work but instead of removing the origin update it to the new link

# Clone the existing project to a new location
git clone originalproject newproject

# Update the remote to the new git repository URL
git remote set-url <remote> <url>

Note

If you have git hooks on your original repository they will not be copied to the new one so you will need to copy them as well.

like image 65
CodeWizard Avatar answered Sep 19 '22 12:09

CodeWizard