You know how to fork a repo, so it is time to talk about cloning. Cloning is often used with the fork command, so you will be using both of these commands together as you continue to work with Git and GitHub. Today’s post continues the “Connecting Your Computer with GitHub” lesson by talking about cloning.
This post will explain what cloning is and why developers want to clone a repo. Skillcrush students then practice cloning a repository with the forked repository they made from the last post.
What is cloning?
A clone on GitHub is a copy of the GitHub repo on your computer. This makes the clone command very important. Developers clone repos when they want to make edits to repos they have saved on their computers.
Before you start cloning repositories, remember that a cloned repository can be changed on the command line. However, clone repositories can’t be changed on GitHub. If you want to make changes to your cloned repositories, those changes need to be added back to the original repository.
Cloning often involves forking, so you’ll often see them being used together when you are working on GitHub. First, developers fork the repo they want to clone. Next, they clone the repo.
What should you do if you don’t need the connection back to the original repo? Skillcrush tells students they can just clone it without forking the original. It means you can make a copy and make changes without those edits going back to the original.
How to Clone a Repo
Step One: Always double-check where you are. Are you on GitHub? Go to GitHub and login into your account.
When you are logged in, find the repo you forked in the last post and double-check you are on this repo. If you haven’t forked a repo, go back to the last post and follow the steps to fork a repo. You can check if you are on the forked repository by looking at the username in the top left corner.
Step Two: Look for a green button that has Code printed on it. Click this button. A pop-up window will appear with different tabs.
Select the SSH key option. Click the icon with two squares overlayed on top of each other next to it. This will copy the URL.
Do you need to make sure that you are copying the right URL? The URL you need will start with git@github.com followed by the owner’s repo name and the name of the GitHub repository.
Step Three: Go to your command line. Next, navigate to where the cloned directory will be going. Skillcrush recommends students put their repositories in Documents or Desktop folders, but you can use whatever works for you.
Type git clone into the command line. Paste the SSH address you copied in the last step. Press Enter when you are done.
git clone git@github.com:redrambles/seasons
Step Four: You are ready to start making edits to the cloned repository you just made. Use the cd command to move into the new cloned repository. Make sure you use the pwd command to help you see what directory you are in.
cd seasons
pwd
Once you are in the right directory, start making updates. Open a file and make changes to your code. Edit this file as much as you like before moving to the last step.
Step Five: When you are finished with your updates, run git status. Type git add to add your changes. Type git commit to create a commit message.
git status
git add holiday.html
git commit -m "Added new holiday page"
Press Enter when youare done. Now you cloned your first repo. You can take time to find more repositories on GitHub and clone them for your GitHub account.
Top comments (0)