Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save programmerShinobi/0a94d4ac182954d7a9423d2d347363f4 to your computer and use it in GitHub Desktop.
Save programmerShinobi/0a94d4ac182954d7a9423d2d347363f4 to your computer and use it in GitHub Desktop.
Steps to Clone a Git Repository and Push for the First Time on a New PC

Steps to Clone a Git Repository and Push for the First Time on a New PC

1. Ensure Git is Installed

If you haven't installed Git on your PC, download and install it from the official Git website.

2. Configure Git

Set your global username and email:

$ git config --list --show-origin
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

3. Clone the Repository

Use the following command to clone the repository to your PC:

$ git clone <repository-url>

Example:

$ git clone [email protected]:username/repository-name.git
  • Replace <repository-url> with the SSH URL of your GitHub repository.

4. Navigate to the Project Directory

Change to the project directory:

$ cd repository-name

5. Set Up SSH Key for GitHub

a. Generate a New SSH Key

If you don’t have an SSH key, generate one:

$ ssh-keygen -t ed25519 -C "[email protected]"
  • When prompted to save the key, press Enter to save it in the default location.
  • If prompted, you may set a passphrase for additional security (optional).

b. Add Your SSH Key to the ssh-agent

Start the ssh-agent and add your SSH key:
```bash
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519
```

c. Copy Your Public SSH Key to the Clipboard

Display your public key:

$ cat ~/.ssh/id_ed25519.pub
  • Copy the output of the key.

d. Add Your SSH Key to Your GitHub Account

1). Go to GitHub SSH settings. 2). Click New SSH key. 3). Paste your public key into the provided field, give it a descriptive name, and click Add SSH key.

6. Change the Remote URL to SSH (If Necessary)

If your repository was cloned using HTTPS, change it to SSH:

$ git remote set-url origin [email protected]:username/repository-name.git

7. Make Changes and Push to GitHub

a. Make Changes to Your Project

Edit or create files in your project directory as needed.

b. Stage the Changes

$ git add .

c. Commit the Changes

$ git commit -m "Your commit message"

d. Push the Changes to GitHub

$ git push origin main
  • Replace main with the correct branch name if your default branch is different.

8. Check the Status of Your Repository

Use the following command to check the status of your repository:

$ git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment