Sourcetree GIT (HTTPS, SSH) - Yash-777/MyWorld GitHub Wiki

Git Clone

When you clone a repository, the files from the remote repository are downloaded to your computer, and a connection is created. This connection requires you to add credentials. You can either use SSH or HTTPS. SSH is recommended.

Clone with SSH/HTTPS:

SSH:   git clone git@gitlab.com:gitlab-tests/sample-project.git
HTTPS: git clone https://gitlab.com/gitlab-tests/sample-project.git

# Clone to Specific Branch # With user as `Yash-777`
git clone -b <feature-branch-Name> git@gitlab.com:gitlab-tests/sample-project.git
git clone -b <feature-branch-Name> https://Yash-777@gitlab.com/gitlab-tests/sample-project.git
Sourcetree Add Account, File Status - filter, Max Diff - Size Limit
Sourcetree logo
Sourcetree - Remote repositories + Add an Account
image
The File Status tab shows all changes as observed by Git. Additionally, you can filter this tab & check your current filter.
Change The Maximum Lines And Size In Options:
Tools > Options > Diff - Change Max Diff Line Count And Change Size Limit (Text)
image

Configure SSH and two-step verification SSH Client Keys

The URL you use to access a repository depends on the connection protocol (HTTPS or SSH) and the distributed version control system. You can find your repository-specific URLs from the repository Source page. The following table shows these URL formats:

HTTPS https://<repo_owner>@bitbucket.org/<accountname>/<reponame>.git
SSH [email protected]:<repo_owner>/<reponame>.gitor
(or)
ssh://[email protected]/<repo_owner>/<reponame>.git
HTTPS - Clone using the web URL. https://github.com/Yash-777/commons-lang
Git Repo- Clone - with HTTPS SourceTree - Tools -> Options -> Authentication
image image

When you access Git Repository with this URL( .git): https://github.com/Yash-777/commons-lang.git leads to following error:

Command: git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks ls-remote https://github.com/Yash-777/commons-lang.git
Output: 
Error: fatal: unable to access 'https://github.com/Yash-777/commons-lang.git/': Failed to connect to github.com port 443 after 21110 ms: Timed out

πŸ”‘ SSH - Use a password-protected SSH key. [email protected]:apache/dubbo.git, ssh-keygen -t rsa -f yash777 -C "[email protected]"
Git Repo- Clone - with SSH SourceTree - Tools -> Options -> General -> SSH Client Configuration
image
You don't have any public SSH keys in your GitHub account. You can add a new public key, or try cloning this repository via HTTPS.
  1. SSH Key: Give path to your SSH key
  2. SSH Client: Change to OpenSSH(/id_rsa) or PuTTY/Plink(/*.ppk)
image

πŸ“Œ Ensure you have a SSH key first. Or create one on the command line:

If you don't have any public SSH keys in your GitHub account. You can add a new public key, or try cloning this repository via HTTPS.

πŸ” What Is an SSH Host Key Fingerprint?

When a server runs SSH, it has one or more host keys (e.g., RSA, ECDSA, ED25519). A fingerprint is a hash (like MD5, SHA-256) of one of those public keys, used to represent it in a shorter, readable form.

SSH host key fingerprints : SSH keys allow you to establish a secure connection between your computer and GitLab. SSH fingerprints verify that the client is connecting to the correct host.

If you're looking to generate an SSH key pair with a specific filename (yash777) and a passphrase (for added security), you can use the ssh-keygen command with the following steps:

  1. Open your terminal or command prompt.
  2. Use the ssh-keygen command with the -t rsa option to specify RSA as the key type, -f yash777 to specify the filename, and -C to add a comment for your key.
ssh-keygen -t rsa -f yash777 -C "[email protected]"

Replace "[email protected]" with your actual email address or any comment you want to add.

  1. It will prompt you to enter a passphrase. Type in a passphrase that you can remember but is strong enough to protect your private key.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
  1. After entering the passphrase, the key pair will be generated, and you'll see output similar to the following:
Your identification has been saved in yash777.
Your public key has been saved in yash777.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX user@hostname
The key's randomart image is:
+---[RSA 3072]----+
|    . .          |
+----[SHA256]-----+
  1. The private key (yash777) and public key (yash777.pub) will be saved in the current directory. The private key (yash777) should be kept secure and not shared, while the public key (yash777.pub) can be distributed to systems where you need to authenticate via SSH.
C:\Yashwanth\.ssh>ssh-keygen -t rsa -f yash777 -C "[email protected]"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in yash777
Your public key has been saved in yash777.pub
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX your_email@example.com
The key's randomart image is:
+---[RSA 3072]----+
|   . .     .oo   |
|  o . .    .+..  |
| o ++        o o.|
|  .oo       .   o|
+----[SHA256]-----+

πŸ“‚ Resulting Files: After running this command, you’ll have:

  • yash777 β†’ your private key (keep this safe! πŸ”)
  • yash777.pub β†’ your public key (share this with servers/services for SSH access)

πŸ›‘οΈ Security Tips:

  • Never share the private key (yash777)
  • Protect it with a passphrase if prompted (extra security)
  • Upload only the .pub file to servers or GitHub, GitLab, etc.

βœ… GitLab UI: When adding an SSH key in GitLab (Edit Profile > SSH Keys > Add new key), you should only paste your public key β€” specifically the contents of the .pub file.

  • File to add: yash777.pub βœ… (public key - for secure access to GitLab)

  • File to never add: yash777 ❌ (this is the private key leads to following error in GitLab UI)

    ⚠️ GitLab UI - Error:

    The form contains the following errors:
    Key type is forbidden. Must be RSA, ECDSA, ED25519, ECDSA_SK, or ED25519_SK
    Key is invalid
    Fingerprint sha256 cannot be generated
    

SSH tends to be a bit faster, so I'd advise using SSH for your primary account and HTTPS for any other accounts if you're having issues with multiple SSH keys.


πŸ” SSH Key Setup & Usage for GitLab/GitHub

πŸ” SSH Key Setup & Usage for GitLab/GitHub

🌐 What is an SSH Host Key Fingerprint?

An SSH fingerprint is a short representation (hash) of a server’s SSH public key, like:

SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This helps verify you're connecting to the correct server, preventing man-in-the-middle attacks.

SSH keys establish a secure connection. SSH fingerprints confirm you're connecting to the correct host.


πŸ“Œ Step 1: Check if You Have an SSH Key Before setting up SSH access, check if you already have an SSH key:

ls ~/.ssh

Look for files like id_rsa.pub, id_ed25519.pub, or any custom-named .pub file.

You can add public SSH keys in your GitHubProfile: SSH and GPG keys or GitLabprofile: Edit Profile β†’ SSH Keys account.


πŸ› οΈ Step 2: Generate a New SSH Key Pair (Custom Name)

If you're creating a new SSH key pair with a custom filename (yash777), follow these steps:

πŸ”§ Terminal Command:

ssh-keygen -t rsa -f yash777 -C "[email protected]"

Replace "[email protected]" with your actual email or any comment to help identify your key.

🧾 Prompt and Example Output:

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in yash777.
Your public key has been saved in yash777.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|    . .          |
+----[SHA256]-----+

πŸ“‚ Resulting Files

File Description
yash777 πŸ” Your private key – keep this safe and secure
yash777.pub πŸ“€ Your public key – use this to connect to servers and services like GitLab or GitHub

πŸ”’ Security Tips

  • ❌ Never share your private key (yash777)
  • βœ… Share only the public key (yash777.pub)
  • 🧠 Use a passphrase when generating the key for added security
  • Keep your .ssh folder and key files permission-restricted (chmod 600)

🧭 Step 3: Add Your SSH Key to GitLab/GitHub

βœ… GitLab Instructions: GitLab UI β†’ Edit Profile β†’ SSH Keys β†’ Add new key

Then:

  • Paste the entire contents of your yash777.pub file into the text field.
  • Give it a descriptive title (e.g., "Work Laptop Key")
  • Click Add key

βœ… What to Add vs. ❌ What NOT to Add

File Action
yash777.pub / id_rsa.pub βœ… Add this – it's your public key
yash777 / id_rsa ❌ Never add this – it's your πŸ” private key

⚠️ GitLab Error When Adding Private Key: If you mistakenly paste your private key, GitLab will show this error:

The form contains the following errors:
Key type is forbidden. Must be RSA, ECDSA, ED25519, ECDSA_SK, or ED25519_SK
Key is invalid
Fingerprint sha256 cannot be generated

πŸ‘‰ This happens because GitLab only accepts valid public keys of supported types.


Launch PuTTYgen from the Windows Programs list and proceed with the following steps.

  • Under "Parameters", increase the "Number of bits in a generated key:" to a minimum value of 2048.
  • Under "Actions" / "Generate a public/private key pair", click "Generate".
  • You will be instructed to move the mouse cursor around within the PuTTY Key Generator window as a randomizer to generate the private key.
  • Once the key information appears, click "Save private key" under "Actions" / "Save the generated key".
  • Save the private key to the desktop as "id_rsa.ppk".
  • The box under "Key" / "Public key for pasting into OpenSSH authorized_keys file:" contains the public key.


SourceTree - Tools - Options - SSH Client configuration - yashGit.ppk

When you get the following error make sure to add SSH key in GITLab UI. or Might be Okta login issue

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks fetch --prune --no-tags origin
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

SourceTree - Tools - Add SSH key - Select an SSH key file to load (OpenSSH key format) yashGit.pub

⚠️ **GitHub.com Fallback** ⚠️