Skip to content

Fork a single sample as a new repository

Hugo Bernier edited this page Nov 7, 2021 · 1 revision

This repository contains a lot of samples that were created since the inception of the SharePoint Framework.

As a result, the total size of this repository may make it cumbersome to work with.

If you'd like to fork your own copy of a single sample so you can customize it to suit your own needs, you can follow these simple steps:

  1. Using your favorite command prompt, change your current directory where you'd like to clone the repository.

  2. Clone the repository, by entering the following command:

    git clone https://github.com/pnp/sp-dev-fx-webparts
  3. Once the repository is cloned, change your current directory to the root of the SPFx Web Parts sample repo:

    cd sp-dev-fx-webparts
  4. Find the path to the sample you wish to extract. For these instructions, we'll use the react-adaptivecards, located under the samples folder, which means that we'll be isolating samples/react-adaptivecards.

  5. Using the path you determined in the previous step, create a new branch from the sample's folder using this command:

    git subtree split --prefix=yoursamplepath -b yoursample-name

    For example, to isolate react-adaptivecards to a new branch with the same name, you would use:

    git subtree split --prefix=samples/react-adaptivecards -b react-adaptivecards

    Note: This operation may take a long time.

  6. While you're waiting for the previous operation to complete, you can create a new repository. This new repository is where your isolated sample will be placed. You can name the repository anything you wish. For the purpose of these instructions, we'll name the new repository my-adaptive-cards.

  7. Once the new repository is created, copy your repository's URL. The URL should look like https://github.com/your-github-username/your-new-repo-name. For example, if you named it my-adaptive-cards, it will look like https://github.com/your-github-username/my-adaptive-cards.

  8. Using the command line, add your new repository as a remote:

    git remote add upstream https://github.com/your-github-username/your-new-repo-name

    For example, using my-adaptive-cards as your repository name:

    git remote add upstream https://github.com/your-github-username/my-adaptive-cards

  9. Push your subtree using the following command:

    git push upstream yoursample-name

    For example, using our sample name react-adaptivecards, you enter:

    git push upstream react-adaptivecards

  10. Your new repository should now have a branch which contains only the sample folder. You can make your changes to the sample to suit your needs.