Git Clone Repository
In this git tutorial, You will learn how to make a clone of remote repository on local system. This will copy all the application files available on remote sever to local system where you can start working.
1. Generate SSH Key Pair
To connect git server, you may need to configure key based login. So that it will not prompt for each time you connect to server.
mimastech@mimastech.com:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mimastech/.ssh/id_rsa):
Created directory '/home/mimastech/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mimastech/.ssh/id_rsa.
Your public key has been saved in /home/mimastech/.ssh/id_rsa.pub.
The key fingerprint is:
99:e7:cd:fe:8e:c6:a0:eb:a0:c7:9f:5d:a3:91:b2:00 mimastech@mimastech.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| o |
| E S . |
| . o.+ |
| .o ..+o= |
| .oo.= =oo |
| .. o*.o.ooo |
+-----------------+
2. Copy Public Key to Remote Server
Now copy newly generaed public key (~/.ssh/id_rsa.pub) on git server under git account. Use the following command to do it.
mimastech@mimastech.com:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub git@remote.example.com /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys git@remote.example.com's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'git@remote.example.com'" and check to make sure that only the key(s) you wanted were added.
3. Clone Remote Repository on Local
Now use the following command to make a clone of remote git repository on local system.
mimastech@mimastech.com:~$ git clone git@remote.example.com:project/app1.git Cloning into 'app1'... warning: You appear to have cloned an empty repository. Checking connectivity... done.
To verify remote url in local copy of code use following command. In results you will see two urls one for fetch and one for push operations.
mimastech@mimastech.com:~/app1$ git remote -v origin git@remote.example.com:project/app1.git (fetch) origin git@remote.example.com:project/app1.git (push)
If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.