Git Tutorial 9 – Git Clone – Get Local Copy Of Remote Repository
As a part of GIT Tutorials End To End, we will learn about another frequently used and important git command “git clone“ in this post.
If you are a beginner in GIT concepts then I will recommend going through the below posts to understand GIT much better.
Git Tutorial 4 – Create A New Git Repository – Git Init Command
Git Tutorial 5 – Know The State Of Working Directory – Git Status
Git Tutorial 6 – Git Add – Add Changes From Working Directory To Staging Directory
Git Tutorial 7 – Git Commit – Save Staging Directory Changes To Local Repository
Git Tutorial 8 – Git Push – Upload Committed Local Repository Changes To Remote Repository Branch
If you want to learn more basic concepts of GIT then please follow the below link:-
Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.
What is GIT CLONE command?
Understand a scenario. There might be many developers in a project and they will have a remote repository where codes from all developers will be merged together and stored. You are a new addition to the team and obviously, you need to start contributing to the same existing remote repository. For this, you need to have a local copy of the remote repository in your local system. This can be done using the “git clone” command.
We have already created a remote repository in the previous post. I will clone the same remote repository in my local system. Please note although I already have a local repository of that remote repository, I can create several local repositories of the same remote repository on the same system.
git clone <url of remote repo>
Create a new directory and run “git status” command.
As the newly created directory is not a git repo we see an error message as above. Now switch to a newly created directory and run the “git clone” command with a remote URL.
As the above remote repository is a public repository it will not ask for any credential details. Now you can go to the created folder where you can see remote repository content has been copied in folder “dummyrepo1” which is the remote repository name. In the remote repo, we have a file “myFile1.txt” which you can see in your local repo now.
If you run “git status” command now you will not see the error as above.
In fact, this cloned local repository is a full-blown local copy of the remote repository and it will have all commit histories. You can run the “git log” command to see all existing commits.
You can verify the above commits from BitBucket. BitBucket shows the first 7 characters of commit id.
When we cloned a remote repository above you must have noticed that a new folder “dummyrepo1” which is actually a remote repo name, was created. That is actually not needed or redundant if you are creating a directory first and then navigating to it and cloning the repo. You can use options with “git clone” command so that the repo will be cloned in the desired folder directly.
git clone <url of remote repo> <folder name of repo>
I did not create any directory first. I directly passed the desired directory name with the git clone as the last parameter (myRemoteRepoName in the above screenshot). Files were directly copied in the directory instead of creating another folder with a remote repo name.
Please subscribe to my YouTube channel Retarget Common to learn from my video tutorials.
Below are important end to end tutorials for Testers:-
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.