How to Fork Github Image

How to Fork Github

Forking is a way to create a personal copy of someone else’s repository that you have permission to fork. A personal copy is controlled by one person, and will always point to the same repository online. Forking a repository is best described as cloning on steroids. It is the easiest way to get started when collaborating on projects with other people.

A companion tutorial to How to Star Github, also available on YouTube. Just because someone hasn’t written a tutorial yet doesn’t mean you shouldn’t be able to read their code. Learn how forks and branches work, why you might want to fork someone else’s project, and how to use GitHub’s search functionality to find the project you are looking for.

Configuring Git to sync your fork with the original repository

When you fork a project in order to propose changes to the original repository, you can configure Git to pull changes from the original, or upstream, repository into the local clone of your fork.

  1. On GitHub.com, navigate to the octocat/Spoon-Knife repository.
  2. Above the list of files, click  Code."Code" button
  3. To clone the repository using HTTPS, under “Clone with HTTPS”, click . To clone the repository using an SSH key, including a certificate issued by your organization’s SSH certificate authority, click Use SSH, then click . To clone a repository using GitHub CLI, click Use GitHub CLI, then click .The clipboard icon for copying the URL to clone a repositoryThe clipboard icon for copying the URL to clone a repository with GitHub CLI
  4. Open Git Bash.
  5. Change directories to the location of the fork you cloned.
    • To go to your home directory, type just cd with no other text.
    • To list the files and folders in your current directory, type ls.
    • To go into one of your listed directories, type cd your_listed_directory.
    • To go up one directory, type cd ...
  6. Type git remote -v and press Enter. You’ll see the current configured remote repository for your fork.$ git remote -v > origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) > origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
  7. Type git remote add upstream, and then paste the URL you copied in Step 2 and press Enter. It will look like this:$ git remote add upstream https://github.com/octocat/Spoon-Knife.git
  8. To verify the new upstream repository you’ve specified for your fork, type git remote -v again. You should see the URL for your fork as origin, and the URL for the original repository as upstream.$ git remote -v > origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) > origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) > upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch) > upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

Now, you can keep your fork synced with the upstream repository with a few Git commands. For more information, see “Syncing a fork.”

Next steps

You can make any changes to a fork, including:

  • Creating branches: Branches allow you to build new features or test out ideas without putting your main project at risk.
  • Opening pull requests: If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

Fork and Clone

Go to the Skeletonwebsite repository on GitHub and click on Fork.

Screenshot of the fork button on GitHub.

Fork will create a copy of the repository in your GitHub account so that you can make changes to the project.

Go to your own GitHub repository and you will see a repository named skeletonwebsite.

Click into this repository and we will now make a local copy of it on your machine by hitting the clone button.

Screenshot of the clone or download dialog window on GitHub.

Copy the HTTPS URL.

Open your terminal or git bash window.

Move to the location on your computer where you want to create a copy of this project.

Run the following command:

git clone https://github.com/userid/skeletonwebsite.git

 Copy

Note: Substitute your GitHub username for userid.

You now have a local copy on your computer.

The folder on your computer will have the same name as the remote repository on GitHub, skeletonwebsite

Change to the project directory:

cd skeletonwebsite

 Copy

Initialize git:

git init

 Copy

Screenshot of the hidden git folder in the project directory.

After running git init you should see a hidden git folder in your skeletonwebsite directory. If you don’t see it, change the settings on your computer to show hidden files and directories.

To see the current status of your local repository, run:

git status

 Copy

This will show if you have any commits that are staged or committed.

Open up the index.html file in your code editor.

Add a heading or a paragraph.

Check the current status with changes applied:

git status

 Copy

You should see that there are changes not staged to be committed with theindex.html file in red.

Screenshot of the project status, with the index file indicated as modified and not staged.

We will now add this change by running:

git add index.html

 Copy

If you want to add multiple files at once then you can run git add .

Run git status:

Screenshot of the project status, with the index file indicated as modified and staged.

Changes have now been staged and are ready to be committed.

Now we can run git commit to commit these changes.

Use the-m flag to add a commit message.

Remember to describe the specific change you made in the git commit message.

git commit -m "added heading to index.html file"

 Copy

Screenshot of the commit message.

To check that everything is up to date, run:

git status

 Copy

Screenshot of the project status, with nothing to commit, the working tree is clean.

This message shows everything is up to date.

We can now push our code to our repository on GitHub.

Before we do this, see what remote repository on GitHub our local repository is connected to:

git remote -v

 Copy

Screenshot of the configuration for the remote repository.

Push Changes

To push our changes to this repository, run:

git push origin master

 Copy

Screenshot of the changes pushed to GitHub.

Find another repository to fork

Fork a repository to start contributing to a project. You can fork a repository to your user account or any organization where you have repository creation permissions. For more information, see “Roles in an organization.”

If you have access to a private repository and the owner permits forking, you can fork the repository to your user account or any organization on GitHub Team where you have repository creation permissions. You cannot fork a private repository to an organization using GitHub Free. For more information, see “GitHub’s products.”

You can browse Explore to find projects and start contributing to open source repositories. For more information, see “Finding ways to contribute to open source on GitHub.”

Conclusion

The process couldn’t be easier, and then you’ll have your own copy of the project’s repositories, ready to be cloned, modified and pushed back upstream.

Similar Posts

0 Comments

No Comment.