Skip to content

Git

To start using Git from your computer, you must enter your credentials (user name and email) to identify you as the author of your work. The user name and email should match the ones you’re using on GitLab.

In your shell, add your user name:

git config --global user.name "your_username"

And your email address:

git config --global user.email "your_email_address@example.com"

To check the configuration, run:

git config --global --list

The --global option tells Git to always use this information for anything you do on your system. If you omit --global or use --local, the configuration is applied only to the current repository.

You can read more on how Git manages configurations in Customizing-Git-Git-Configuration

Generate an SSH key pair#

If you do not have an existing SSH key pair, generate a new one.

  1. Open a terminal.
  2. Type ssh-keygen -t followed by the key type and an optional comment. This comment is included in the .pub file that’s created. You may want to use an email address for the comment.

    For example, for ED25519:

    ssh-keygen -t ed25519 -C "<comment>"
    
  3. Press Enter. Output similar to the following is displayed:

$ ssh-keygen -t ed25519 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
  • Accept the suggested filename and directory, unless you are generating a deploy key or want to save in a specific directory where you store other keys.

    You can also dedicate the SSH key pair to a specific host.

  • Specify a passphrase:

    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    

A confirmation is displayed, including information about where your files are stored.

Add an SSH key to your Git platform account#

To use SSH with GitLab, add your public key to your GitLab account settings.

  1. Copy the contents of your public key file. You can do this manually or use a script. For example, to copy an ED25519 key to the clipboard:

    macOS:

    tr -d '\n' < ~/.ssh/id_ed25519.pub | pbcopy
    
    Linux (requires the xclip package):
    xclip -sel clip < ~/.ssh/id_ed25519.pub
    
    Git Bash on Windows:
    cat ~/.ssh/id_ed25519.pub | clip
    

  2. Replace id_ed25519.pub with your filename. For example, use id_rsa.pub for RSA.

  3. Sign in to GitLab.
  4. In the top-left corner, select your avatar.
  5. Select Settings.
  6. From the left sidebar, select SSH Keys.
  7. In the Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with ssh-ed25519 or ssh-rsa, and may end with a comment.
  8. In the Title text box, type a description, like Work Laptop or Home Workstation.
  9. Optional. In the Expires at box, select an expiration date. (Introduced in GitLab 12.9.) The expiration date is informational only, and does not prevent you from using the key. However, administrators can view expiration dates and use them for guidance when deleting keys.
  10. Select Add key.

To use SSH with GitHub, add your public key to your GitHub account settings.

  1. Copy the contents of your public key file. You can do this manually or use a script. For example, to copy an ED25519 key to the clipboard:

    macOS:

    tr -d '\n' < ~/.ssh/id_ed25519.pub | pbcopy
    
    Linux (requires the xclip package):
    xclip -sel clip < ~/.ssh/id_ed25519.pub
    
    Git Bash on Windows:
    cat ~/.ssh/id_ed25519.pub | clip
    

  2. Replace id_ed25519.pub with your filename. For example, use id_rsa.pub for RSA.

  3. Sign in to GitHub.
  4. In the top-right corner, select your avatar.
  5. Select Settings.
  6. From the left sidebar, select SSH and GPG keys.
  7. Click New SSH key.
  8. In the Title field, add a descriptive label (e.g., Work Laptop or Home Workstation).
  9. In the Key field, paste your public key. Ensure the entire key is copied, starting with ssh-ed25519, ssh-rsa, or similar.
  10. Select Add SSH key.