1. Using other repos
Welcome back! We've learned how to modify a repo. We'll now look at collaborating with other repos.
2. Cloning
Cloning a repo is similar to copy-paste; however, it has a link to the original repo. It creates a copy of the repo in its current state on our local computer and allows us to send updates back and forth.
We can work on the files locally, push changes back to the repo, or pull any new updates to our local version using Git. Anyone can clone a public repo, but a private repo owner needs to grant access.
3. Clone a repo
Here, we are viewing George Boorman's bank marketing private repo. To clone it,
4. Clone a repo
we navigate to the dropdown menu in the green Code button.
5. Clone a repo
The HTTPS tab is already selected. We need to copy the URL provided
6. Clone a repo
by clicking on the copy icon next to it.
7. Clone a repo
Next, we open our terminal window, where we need to use Git to perform the clone. First, we check we are in the correct directory, then type the command git clone followed by the URL we copied from GitHub and hit enter. We may be prompted to enter our GitHub username and personal access token. We hit enter again to initiate the clone.
8. Clone an empty repo
If the repo we are cloning is empty, we will follow similar steps, except that the link we need to copy will appear on the repo's main page within a blue box called Quick Setup.
9. Forking
We can copy a repo without linking back to it. In GitHub, this is called forking. A fork of a repo creates an independent copy of it on our GitHub, meaning we can run experiments without the risk of anything reaching the original repo.
This option is often used for collaboration. Anyone with a GitHub account can fork a public repo, but the owner of a private repo needs to allow this feature. For public repos, this opens up the opportunity for a lot of collaboration if anyone finds our repo and has an idea. After forking, a contributor can make changes to the project and submit them through a pull request. Forking differs from creating a new branch where we need to be registered as project collaborators.
10. Fork a repo
We are back in the bank marketing repo we want to fork. George has kindly allowed the forking feature in this private repo.
11. Fork a repo
We navigate to the Fork button in the top-right.
12. Fork a repo
In the dropdown, we select Create a new fork.
13. Fork a repo
If we are part of any organization, we may see several options in a dropdown list to select the owner; otherwise, there should only be one option. The default name will be the same as the repo we are forking from.
14. Fork a repo
We should amend this to tell the difference. We will leave the description blank.
15. Fork a repo
Finally, we can select the branch we want to fork from. As there is only one main branch, we choose that one. The default is to fork from the main branch if there are multiple branches.
16. Fork a repo
Then, click Create fork.
17. Fork a repo
We have successfully created an independent copy of George's bank marketing repo. To work on this project on our computer, we can follow the previous steps to clone it.
18. Clone vs. Fork
To recap, we have two ways to copy a repo. Cloning creates a linked copy on our computer, requires using Git, and updates are sent via the push and pull commands on Git. Forking creates an independent copy on GitHub, and changes are submitted through a pull request or PR. Both are great for collaboration, but forking allows for safer experimentation.
19. Let's practice!
Time for practice!