Recently, I ran into a recurring and frustrating HTTP 400 RPC failed error when trying to git push my changes to GitHub, particularly from my JetBrains IDE (like IntelliJ IDEA or WebStorm). What made it especially confusing was that it had been working perfectly until last week!

If you’re seeing errors like:

error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

…and you’ve already tried generating new Personal Access Tokens or re-authenticating in your IDE, this guide is for you.

The Problem: Network Interference with HTTPS

My deep dive revealed that the HTTP 400 Bad Request error, especially when it pops up unexpectedly, often points to network-level interference. While HTTPS is generally secure, proxies, firewalls, VPNs, or even changes from an ISP can sometimes inspect or corrupt the Git data packets, making GitHub’s servers reject the request as “malformed.”

The good news is there’s a more resilient way to connect.

The Solution: Switching to SSH for GitHub

The SSH (Secure Shell) protocol provides a more direct and encrypted channel for Git operations, making it far less susceptible to the kind of network interference that causes HTTP 400 errors with HTTPS.

Here’s the step-by-step process I followed to switch my local repositories to SSH, ensuring smooth sailing for pushes and pulls from now on. You’ll need to do these steps for each computer you use to interact with GitHub.


Step 1: Generate a Unique SSH Key Pair for Your Machine

Each computer needs its own unique key pair. Do not copy keys between machines!

  1. Open your Terminal (macOS/Linux) or Git Bash (Windows).
  2. Generate the key: Run the following command. Replace "your_email@example.com" with the email associated with your GitHub account.

    ssh-keygen -t ed25519 -C "your_email@example.com"
    
    • Prompt for file to save the key: Just press Enter to accept the default location (~/.ssh/id_ed25519).
    • Prompt for passphrase: You can press Enter twice to leave it blank (recommended for simplicity with Git), or set a strong passphrase for extra security (you’ll be prompted for it every time you use the key).

    You should see output like:

    Your public key has been saved in /Users/YOUR_USERNAME/.ssh/id_ed25519.pub
    

    This creates two files: id_ed25519 (your private key) and id_ed25519.pub (your public key).

Step 2: Add Your New Public SSH Key to Your GitHub Account

Now, we need to tell GitHub about your computer’s public key so it recognizes you.

  1. Copy your public key to your clipboard:
    • On macOS:
        pbcopy < ~/.ssh/id_ed25519.pub
      
    • On Windows (using Git Bash or WSL):
        cat ~/.ssh/id_ed25519.pub | clip
      

      (If clip doesn’t work, open ~/.ssh/id_ed25519.pub with a text editor and copy the entire content.)

  2. Go to GitHub’s SSH settings:
    • Open your web browser and navigate to github.com/settings/keys.
    • You’ll likely need to re-enter your GitHub password.
  3. Add the new key:
    • Click the New SSH key button.
    • Title: Give your key a descriptive name (e.g., “My iMac’s Key”, “MacBook Air SSH”, “Work Desktop”). This helps you identify which machine is which.
    • Key: Paste the public key you copied from your clipboard into the large text area.
    • Click Add SSH key.

    You should now see your new key listed.

Step 3: Update Your Local Git Repository to Use the SSH URL

Finally, you need to tell your local Git project to use the SSH address instead of the HTTPS one.

  1. Open your Terminal/Git Bash and navigate to your local Git repository’s root directory (e.g., cd YOUR_USERNAME.github.io).

  2. Verify your current remote URL (optional):
    git remote -v
    

    You’ll likely see something like https://github.com/YOUR_USERNAME/YOUR_USERNAME.github.io.git.

  3. Set the new SSH remote URL: Run this command, ensuring YOUR_USERNAME is your GitHub username and YOUR_USERNAME.github.io is your repository name:

    git remote set-url origin git@github.com:YOUR_USERNAME/YOUR_REPOSITORY.git
    
  4. Verify the new remote URL (optional):
    git remote -v
    

    You should now see something like git@github.com:YOUR_USERNAME/YOUR_USERNAME.github.io.git.

Step 4: Perform Your First SSH Push (and accept the host fingerprint)

Now, try your git push again, either from your IDE or the terminal.

git push

Contact Dr. Kahveci