Trusted answers to developer questions
Get Started With Data Science
Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.
In a scenario where we want to download an existing Git repository to our local computer, we aim to create a clone or duplicate of the Git repository so that we can start working on it whenever convenient. Whether you’re fixing merge conflicts, adding or removing files, or making substantial commits on Git, cloning ensures you have a local copy to work with. In this Answer, we’ll explore how to clone a Git repository using the command line.
The git clone
command
Git provides git clone
command to clone a repository that is already present on GitHub.
git clone {repository URL}
This command cloned all of the folders, files, commits and branches of the specified repository. You just need to replace {repository URL}
with your GitHub repository link.
Cloning a repository using the command line
Now we’ll focus on cloning a repository using a command line. Follow the directions below:
- Open GitHub and go to the GitHub repository that you want to clone.
- Click “Code” and copy the given URL.
Click "Code" and copy the URL
If we want to clone an empty repository, click the "copy icon" as shown in the given illustration:
Clone an empty repository
- Open “
” and change the current working directory to the location where you want the cloned directory.Git Bash Git Bash is a command-line interface for Git. - Type “git clone” in the terminal, paste the URL you copied earlier, and press “enter” to create your local clone.
Hands-on practice
To gain hands-on experience, you can clone any repository using the following terminal. Simply specify the URL of your desired repository in the git clone
command. To verify the cloned repository, use the ls
command to view the contents of the directory where you cloned it.
Terminal 1
Terminal
Loading...
RELATED TAGS
github
CONTRIBUTOR
Aparna Pannir
Keep Exploring
Related Courses
TRENDING TOPICS
Copyright ©2024 Educative, Inc. All rights reserved.
Did you find this helpful?