Install Git for Windows, Create SSH Keys, and Set Up Your First Repo

  • Thread Author

Install Git for Windows, Create SSH Keys, and Set Up Your First Repo​

Difficulty: Beginner | Time Required: 15 minutes
Git is the backbone of modern software development on Windows. With Git for Windows, SSH keys, and a first repository set up, you’ll be ready to track changes, collaborate with others, and push code to GitHub, GitLab, or Bitbucket. This guide walks you through everything from installation to your first commit and remote push, in clear, friendly steps.
Introduction
  • Why you’ll love this: Git helps you track changes, revert when needed, and collaborate without losing work. SSH keys provide secure, password-free authentication to your remote repositories. By the end, you’ll have a working local repo and a remote on your preferred hosting service.
Prerequisites
  • Windows 10 or Windows 11 PC with internet access. If you’re on Windows 10, ensure you’re on a fairly recent build (OpenSSH client can be enabled as an optional feature if you prefer using Windows tools directly). On Windows 11, the OpenSSH client is typically available by default.
  • A Git hosting account (GitHub, GitLab, or Bitbucket) is optional for this tutorial’s remote steps, but recommended if you want to push your first repo online.
  • Optional but helpful: VS Code or another code editor installed for editing files.
Step-by-step Instructions
1) Install Git for Windows
  • Go to the official download page: git-scm.com
  • Download the 64-bit Git for Windows Setup (most users will want this).
  • Run the installer. For most users, select:
    • “Use Git from the Windows Command Prompt” (so you can run git from CMD or PowerShell) or keep “Git Bash only” if you prefer Bash.
    • “Checkout Windows-style, commit Unix-style line endings” (recommended if you’ll share code across Windows and Unix-like systems).
    • “Use OpenSSL” for HTTPS/S-sha256 verification (default).
    • “Git Credential Manager Core” (will store credentials securely in Windows Credential Manager).
  • Complete the installation and finish.
  • Verify installation: open Command Prompt or Git Bash and type:
    • git --version
      You should see the installed Git version, confirming success.
2) Configure Git globally
  • Open Git Bash (or CMD/PowerShell) and set your identity:
    • git config --global user.name "Your Name"
    • git config --global user.email "you@example.com"
  • Optional quality-of-life tweaks:
    • git config --global core.editor "code --wait" (if you use VS Code)
    • git config --global color.ui auto
  • This configuration is saved in your user profile and applies to all repos on this machine.
3) Create SSH keys for secure remote access
  • Why SSH keys? They replace password-based authentication with a secure, token-like method that’s easier to automate.
  • Generate a new SSH key (Ed25519 is recommended for security and efficiency):
    • Open Git Bash.
    • Run: ssh-keygen -t ed25519 -C "you@example.com"
    • When prompted for a file to save the key, press Enter to accept the default: /c/Users/YourUser/.ssh/id_ed25519
    • Enter a passphrase (optional but recommended) for added security, then re-enter it.
  • Start the SSH agent and add your key:
    • eval "$(ssh-agent -s)"
    • ssh-add ~/.ssh/id_ed25519
  • Copy your public key to the clipboard:
    • cat ~/.ssh/id_ed25519.pub | clip
    • The clip command copies to Windows clipboard; if you don’t have clip, you can open id_ed25519.pub with a text editor and copy manually.
  • Add the key to your hosting service:
    • GitHub: Settings > SSH and GPG keys > New SSH key > paste key > Save
    • GitLab/Bitbucket: similar path to add an SSH key
  • Test the connection:
    • ssh -T git@github.com
    • You may see a warning about authenticity; type yes to continue. You should see a welcome message like: Hi your-username! You’ve successfully authenticated, but GitHub does not provide shell access.
Note for Windows 10/11 users
  • Windows 10 (1809+) can enable the built-in OpenSSH Client via Settings > Apps & Features > Optional Features > Add a feature > OpenSSH Client. If you prefer using Windows OpenSSH instead of Git Bash for SSH, you can generate and manage keys with PowerShell, then use the SSH keys in your Git tooling.
  • If you run into issues with ssh-agent on Windows, you can also rely on the Git Credential Manager Core to handle SSH keys in some setups. The Git installer’s defaults generally work for most users.
4) Set up your first local repository and push to remote
  • Create a project folder and initialize a repository:
    • mkdir MyFirstRepo
    • cd MyFirstRepo
    • git init
  • Create a basic project file (and a README):
    • echo "# MyFirstRepo" > README.md
    • echo "This is my first Git repo on Windows." > hello.txt
  • Create a .gitignore (optional but recommended):
    • For example, if you’re in a Node.js project, you might echo "node_modules/" > .gitignore
    • If you’re not sure, you can skip this step or tailor it to your project later.
  • Stage and commit your files:
    • git add .
    • git commit -m "Initial commit with README and greeting"
  • Connect to a remote repository (GitHub, GitLab, etc.:
    • If you created a remote repository, copy the SSH URL (it should look like git@github.com:username/MyFirstRepo.git).
    • Add the remote: git remote add origin git@github.com:username/MyFirstRepo.git
    • If your remote is HTTPS, use the HTTPS URL and enter your credentials when prompted (Git Credential Manager will save them).
  • Push to the main branch:
    • git branch -M main
    • git push -u origin main
  • Verify:
    • git remote -v should show the origin URL
    • Open your remote hosting page to confirm the files appeared
Tips and troubleshooting notes
  • If Git Bash isn’t your preferred shell, you can use Windows Terminal or PowerShell with Git from the Command Prompt option chosen during installation. The basic Git commands are the same.
  • SSH key not recognized? Ensure the ssh-agent is running and that the key is added (ssh-add ~/.ssh/id_ed25519). If you restarted your computer, you may need to re-run ssh-agent and ssh-add.
  • If you get “Permission denied (publickey)” when pushing, double-check:
    • The correct SSH key is added to the hosting service account
    • The remote URL uses SSH (git@host:username/repo.git). If you used HTTPS, you’ll authenticate with your username/password or token.
  • Windows path length: some Windows environments may complain about long paths. It’s solved by enabling long path support in Windows or choosing a shorter directory path for your repo.
  • If you prefer GUI tools, GitHub Desktop, GitLab Runner, or similar can make cloning and pushing simpler. This tutorial sticks to the command line for portability and speed, but GUI tools are perfectly fine to complement these steps.
  • Keep your SSH key secure: never share your private key (~/.ssh/id_ed25519) and use a passphrase for extra protection. If you ever suspect compromise, revoke the key on your hosting service and add a new one.
Conclusion
With Git for Windows installed, SSH keys configured, and your first local repository linked to a remote host, you’re ready to version and share your code with confidence. You’ve gained a foundation for future projects, collaboration, and efficient development workflows across Windows 10 and 11 environments.
Key Takeaways:
  • Git for Windows provides a fast, reliable way to track changes locally and collaborate remotely.
  • SSH keys enable secure, password-free authentication to your remote repositories.
  • A simple first repo demonstrates the full cycle: init, add, commit, remote, and push.

This tutorial was generated to help WindowsForum.com users get the most out of their Windows experience.
 

Back
Top