top of page

Git Clone

Git Clone is typically used to create a copy of a local or remote repository. "git clone" creates a copy of files and folders based on the committed changelog in the repository.

That means during git clone ensures to copy only committed data by skipping unstaged/untracked/.gitignore files & folders.


  • Git Clone Local Repository

To clone a local repository, run the following command, which will clone the local repository to a new repository.


I'll try to clone the local repository MyProject1 to MyProject2.

[root@siddhesh ~]# ls -d MyProject1/
MyProject1/
[root@siddhesh ~]# git clone MyProject1 MyProject2
Cloning into 'MyProject2'...
done.
[root@siddhesh ~]# ls -alhrt MyProject2/
total 12K
-rw-r--r--. 1 root root  0 Feb 12 07:01 production.log
-rw-r--r--. 1 root root 10 Feb 12 07:01 myscript.py
-rw-r--r--. 1 root root 20 Feb 12 07:01 myscript3.py
-rw-r--r--. 1 root root 11 Feb 12 07:01 myscript2.py
-rw-r--r--. 1 root root  0 Feb 12 07:01 index.php
[root@siddhesh ~]# 

As you can see here now after cloning MyProject1 to MyProject2 we got a new folder MyProject2 with all committed changes to the repository of MyProject1.


  • Git Clone Remote Repository

We can also use "git clone" to clone a remote repository. A remote Git server, GitHub, or GitLab could be used.


In the following example, I will use the git token to clone my private GitHub repository. as "git clone" has stopped Password authentication was deactivated on August 13, 2021.

If you want to clone a private repository from GitHub, use the following syntax:

[root@siddhesh ~]# git clone https://<token key>@github.com/<username>/<name of repository>.git <local folder path to cloen>

[root@siddhesh ~]# git clone https://<GitHub Token Key>@github.com/siddheshkadam/Python3.git MyProject3
Cloning into 'MyProject3'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 18 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (18/18), done.
[root@siddhesh ~]# ls -lhrta MyProject3/
total 32K
dr-xr-x---. 16 root root 4.0K Feb 12 07:22 ..
-rw-r--r--.  1 root root 1.9K Feb 12 07:22 report.py
-rw-r--r--.  1 root root    9 Feb 12 07:22 README.md
-rw-r--r--.  1 root root 2.7K Feb 12 07:22 mail_trans.py
drwxr-xr-x.  8 root root  163 Feb 12 07:22 .git
-rw-r--r--.  1 root root 2.5K Feb 12 07:22 fortimail_api.py
-rw-r--r--.  1 root root 9.3K Feb 12 07:22 dominfo.py
drwxr-xr-x.  3 root root  115 Feb 12 07:22 .
[root@siddhesh ~]# 

Note: The private key is masked for security reasons. The output above shows that a new folder MyProject3 was created with an exact replica of my personal GitHub private repository.



bottom of page