Git - Clone Operation
Git - Clone Operation
Section titled “Git - Clone Operation”Assuming a remote Git repository exists (e.g., on a server or a hosting service like GitHub, GitLab, or Bitbucket) and Tom has pushed his initial version. Now, Jerry wants to get a local copy of this repository. The git clone command creates a local copy (a “clone”) of the remote repository, including all its files, branches, and history.
Jerry creates a new directory for his projects and then performs the clone operation using the repository’s URL. This URL can be HTTPS or SSH.
[jerry@devbox ~]$ mkdir my_projects[jerry@devbox ~]$ cd my_projects/
[jerry@devbox my_projects]$ git clone https://git.example.com/tom/project.gitThe above command will produce output similar to this:
Cloning into 'project'...remote: Counting objects: 3, done.remote: Compressing objects: 100% (2/2), done.remote: Total 3 (delta 0), reused 0 (delta 0)Receiving objects: 100% (3/3), done.Git creates a new directory named project (derived from the repository URL), downloads the data, and checks out the latest version of the default branch (commonly named main). Jerry then changes the directory to this new local repository and lists its contents.
[jerry@devbox my_projects]$ cd project/
[jerry@devbox project]$ lsREADME.mdHis local repository is now connected to the remote repository (which Git automatically names origin). He can start working on the files, and later push his changes or pull updates from others.