How to Clone a Repo to Another Repo Updated

How to Clone a Repo to Another Repo

Co-author: Eileen Chu

Photo by Caleb White on Unsplash

In this exercise, you will follow the steps beneath:

  • Add your website files to Git Repo
  • Launch an EC2 Instance through the AWS Console
  • SSH to EC2 Example & Install a Web Server
  • Install Git on the EC2 Example
  • Clone a Repo from Git onto the EC2 Example

Add your website files to Git Repo

Before adding, you will have to create a new repo on your GitHub. On your local machine, initialize a Git directory:

          $ git init        

To check the land of the working directory and the stage area, enter:

          $ git status        

And then add the unabridged project under git tracking:

          $ git add .        

Now you can commit the file:

          $ git commit -m "this is my first commit"        

Your site is at present under version control.

          $ git remote add origin <repo URL>        

And Push the changes in your local repository to GitHub if needed.

          $ git push -u origin master    # before Oct 2020
or
$ git button -u origin primary # later Oct 2021

Note: GitHub renamed the default branch from "master" to "primary" in October 2020. Since my project was before renaming, my default branch is "principal". If you recently created a repo, the default branch will exist "chief".

Here is a style to handle
https://stevenmortimer.com/5-steps-to-change-github-default-branch-from-master-to-main/

To cheque the commit history, enter:

          $ git log        

Launch an EC2 Instance through the AWS Console

Follow the steps in the 'Launch an EC2 Instance' department of Practice 1. In the final footstep, you can utilize the fundamental-pair file straight from the previous practice so that you don't need to create a new key-pair.

SSH to EC2 Instance & Install a Web Server

Follow the steps in the 'SSH to EC2 Example' and 'Install a Web Server' section of Practise one.

Install Git on the EC2 Instance

Install Git in your EC2 instance with the following command:

          yum install git -y        

Clone a Repo from Git onto the EC2 instance

In Practice 1, as you can remember that the Apache Spider web Server will display the index.html file plant in /var/www/html root path of your website by default.

You volition clone the repository you created before into that directory.

1. Navigate to the directory

          cd /var/www/html        

two. Clone the contents of the Repo into this directory using SSH.

(Note: The '.' at the terminate of the command is to put the contents of the repository into the current directory)

          git clone            git@github.com:<your_git_user_name>/<repo_name>.git .        

At this point, an error might occur — already exists and is not an empty directory.

That is to say, y'all should remove the existing alphabetize.html before you clone:

          rm index.html        

After removing, clone again. However, you might withal get some other error bulletin telling you this won't work considering Github will not find an appropriate SSH key on your EC2 instance to cosign your access. Thus, you will need to generate private and public SSH keys on your instance and add the public key to Github.

3. Generate your SSH keys on the EC2 instance

Run the following commands to generate your SSH keys on the EC2 instance (Note: Larn more about SSH key generatio n — ssh-keygen ):

          ssh-keygen -t rsa -C "your-e-mail@gmail.com"        

You will exist asked some questions every bit follows:

To specify the location where your cardinal is stored. Press Enter straight abroad here.

          Generating public/private rsa fundamental pair.
Enter file in which to save the key (/home/seal/.ssh/id_rsa):

To specify the key protection countersign. If yous have configured the further security settings, you must enter the password. Otherwise, press Enter to go on the default setting.

          Enter passphrase (empty for no passphrase):        

Press Enter over again, and then the key will be generated.

          Enter same passphrase again:        

The generated key includes two files:

  • id_rsa:This is the individual cardinal, which should be kept hush-hush and only tin can be used past yourself.
  • id_rsa.pub:This is the public primal. Y'all make it public then that others tin verify that a given signature which comes from your private key.

In particular, your private fundamental is used to sign things, and your public fundamental is used to verify your signature. (Know more about individual and public keys )

Switch to the root user and access your SSH public key by using the command beneath:

          sudo su
cat ~/.ssh/id_rsa.pub

4. Add the Public SSH key to your Github Business relationship

Follow the steps on this folio.

5. Clone the repository into your EC2 Instance

To connect to AWS, open your Last (if you are using Windows, run commands in Git Bash) and run the command:

          ssh -i ~/MyKeyPair.pem ec2-user@<your-ip-address>        

Modify your directory to where the index.html file is:

          cd /var/www/html        

Switch to the root user and remove all files:

          sudo su
rm -rf *

Recollect to remove hidden files too (just keep . and .. in the directory):

          ls -a
rm -rf .git

At present you are able to clone your updated file into the current directory:

          git clone            git@github.com:<your_git_user_name>/<repo_name>.git .        

Enter your DNS (IPv4) of your example into the browser, then you tin see the website that you pushed to GitHub.

Support my writing by becoming a Medium fellow member today and getting access to an unlimited number of articles.

How to Clone a Repo to Another Repo

Posted by: fostersaithe.blogspot.com

0 Response to "How to Clone a Repo to Another Repo Updated"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel