DEV Community

YuIT Solutions
YuIT Solutions

Posted on • Edited on

Create a new SSH key🔑 and first commit to GitHub

Create a new SSH connection between your local machine and GitHub

1️⃣ Open the Git Bash and generate a New SSH Key

cd C:\MyPath\GitHub\ (it's custom path for ssh key)
ssh-keygen -t ed25519 -C "my-key"
Enter fullscreen mode Exit fullscreen mode
  • Enter file in which to save the key (C:\Users\someuser.ssh\id_ed25519): C:\MyPath\GitHub\key
  • C:\MyPath\GitHub\key already exists.
  • Overwrite (y/n)? y

2️⃣ Add SSH Key to SSH Agent
Start the ssh-agent:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Add your new SSH private key:

ssh-add key
Enter fullscreen mode Exit fullscreen mode

3️⃣ Copy the SSH Public Key

cat key.pub | clip
Enter fullscreen mode Exit fullscreen mode

4️⃣ Add the SSH Key to Your GitHub Account

  • Log in to GitHub
  • Go to Settings > SSH and GPG keys
  • Click New SSH key
  • Paste your key into the "Key" field
  • Add a descriptive title
  • Click Add SSH key

5️⃣ Test the SSH Connection

ssh -T [email protected]
Enter fullscreen mode Exit fullscreen mode

Summary:

- Generate SSH key (ssh-keygen)
- Add key to SSH agent (ssh-add)
- Copy public key (cat ~/.ssh/id_ed25519.pub) and add to GitHub
- Test connection (ssh -T [email protected])
- Use SSH URL for repositories
Enter fullscreen mode Exit fullscreen mode

Guide to add a file, commit your changes, and prepare for pushing to GitHub:

Step 1. Clone your Repositories

git clone [email protected]:username/repository.git
Enter fullscreen mode Exit fullscreen mode

Step 2. Add your new or modified files

To stage a specific file:

git add filename
Enter fullscreen mode Exit fullscreen mode

To stage all changed files:

git add .
Enter fullscreen mode Exit fullscreen mode

Step 3. Commit your changes with a descriptive message:

git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

Step 4. Push your changes to GitHub

git push origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)