Create a new SSH connection between your local machine and GitHub
1️⃣ Open the Git Bash and generate a New SSH Key
cd ~/.ssh or cd C:\MyPath\GitHub\ (it's custom path for ssh key)
ssh-keygen -t ed25519 -C "my-key"
- 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 (Configure SSH to point to a different directory)
Start the ssh-agent:
eval "$(ssh-agent -s)"
Add your new SSH private key:
ssh-add key
3️⃣ Copy the SSH Public Key
For windows
cat key.pub | clip
For macos
cat key.pub | pbcopy
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
Or add the SSH Key to Your GitLab Account
- Sign in to GitLab
- On the left sidebar, select your avatar
- Select Edit profile
- On the left sidebar, select SSH Keys
- Select Add new key
- Select Key, and you should see the 1Password helper appear
- Select the 1Password icon and unlock 1Password.
- You can then select Create SSH Key or select an existing SSH key to fill in the public key
5️⃣ Test the SSH Connection
ssh -T git@github.com
or
ssh -T git@gitlab.com
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 or Gitlab
- Test connection (ssh -T git@github.com or ssh -T git@gitlab.com)
- Use SSH URL for repositories
Guide to add a file, commit your changes, and prepare for pushing to GitHub:
Step 1. Clone your Repositories
git clone git@github.com:username/repository.git
Step 2. Add your new or modified files
To stage a specific file:
git add filename
To stage all changed files:
git add .
Step 3. Commit your changes with a descriptive message:
git commit -m "Your commit message"
Step 4. Push your changes to GitHub
git push origin main
Top comments (0)