# 🚀 Git Errors & Solutions – A Handy Developer Guide

## 🔧 1. HTTP Post Buffer Error

**🛑 Error Message:**

```bash
RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
fatal: the remote end hung up unexpectedly
```

### 💡 What It Means:

This usually happens when you're pushing **large files** (e.g., videos, high-res images, binaries) to a Git remote like GitHub. Git uses HTTP under the hood, and by default, it can't handle large payloads.

### ✅ How to Fix It:

#### ➤ **Temporary Fix (Just for This Push):**

```bash
git -c http.postBuffer=524288000 push origin main
```

* `http.postBuffer=524288000` sets buffer to 500MB for **this command only**.
    

#### ➤ **Permanent Fix (All Pushes):**

```bash
git config --global http.postBuffer 524288000
```

* Adds this setting to your **global Git config**, so it always uses a bigger buffer.
    

> ✅ Tip: If the file is still too large, consider using [Git Large File Storage (LFS)](https://git-lfs.github.com/).

---

## 🔐 2. **fatal: repository not found**

### 💡 What It Means:

Git is trying to push or pull from a remote repo, but it **can't find it**. Most likely causes:

* The URL is wrong.
    
* You're not authenticated (especially if private).
    
* Wrong GitHub credentials are cached.
    

### ✅ How to Fix:

#### 🪪 Fixing Credentials (Windows):

1. Open **Credential Manager** (search in Start).
    
2. Go to **Windows Credentials** &gt; find anything starting with `git:` or `github.com`.
    
3. Delete those entries.
    
4. Try `git push` again — Git will ask for username/password or personal access token.
    

> 🔐 GitHub no longer accepts passwords — use a **Personal Access Token (PAT)** instead.

---

## 📂 3. **fatal: not a git repository**

### 💡 What It Means:

You're trying to run Git commands (like `status`, `add`, `push`), but Git can't find the `.git/` folder — the folder that tracks your repository data.

### ✅ How to Fix:

#### Step 1: Check You're in the Right Folder

```bash
ls -a
```

If you **don’t see a** `.git` folder, you’re probably:

* In the wrong directory.
    
* Or accidentally deleted it.
    

#### Step 2: Re-Initialize the Repository

If `.git` is missing:

```bash
git init
git remote add origin https://github.com/user/repo.git
git fetch origin
```

---

## 😬 4. **Committed to the Wrong Branch**

### 💡 What It Means:

Oops! You meant to commit to `dev`, but committed to `main`.

### ✅ How to Fix:

#### Step 1: Get the Commit ID

```bash
git log --oneline
```

Find the commit(s) you mistakenly made.

#### Step 2: Switch to Correct Branch

```bash
git checkout dev
```

#### Step 3: Cherry-Pick the Commit

```bash
git cherry-pick <commit-id>
```

#### Step 4: Go Back to `main` and Undo the Commit

```bash
git checkout main
git reset --hard HEAD~1
```

> ⚠️ `--hard` resets your working directory too. Make sure you've cherry-picked already.

---

## 🚫 5. **File Ignored by** `.gitignore`

### 💡 What It Means:

You’re trying to add a file (e.g., `3.txt`) but Git won’t track it. That file is probably listed in your `.gitignore`.

### ✅ How to Fix:

#### Force Git to Track the File:

```bash
git add -f 3.txt
```

The `-f` flag = **force add**, overriding `.gitignore`.

> 📝 If this is permanent, remove the file from `.gitignore` too.

---

## 🔁 6. **Conflict When Two People Push**

### 💡 What It Means:

Two people clone the same repo. Both make changes on `main`. The first person pushes fine. The second person gets an error.

**Why?** Because the second person’s history is now out of sync — Git doesn't know how to merge the changes safely.

### ✅ How to Fix:

#### Step 1: Rebase Your Changes

```bash
git pull --rebase origin main
```

#### Step 2: Fix Any Conflicts

If Git says there are merge conflicts:

* Open the files.
    
* Fix the conflicting lines.
    
* Save, then run:
    

```bash
git rebase --continue
```

#### Step 3: Push Again

```bash
git push origin main
```

> 👍 Rebase creates a **cleaner history** than merge.

---

## 🌐 7. **Change Git Remote URL**

### 💡 Why You Need This:

You may switch between HTTPS and SSH, or maybe you moved to a new Git server (e.g., from GitHub to GitLab).

### ✅ How to Check Current URL:

```bash
git remote -v
```

### ✅ How to Change It:

```bash
git remote set-url origin <new-url>
```

### ➕ Example:

Switch from HTTPS to SSH:

```bash
git remote set-url origin git@github.com:user/repo.git
```

---

## 🧹 8. **Deleting and Recovering Branches**

### 🔥 Delete Remote Branch:

```bash
git push origin --delete <branch-name>
```

### 🧹 Delete Local Branch:

```bash
git branch -D <branch-name>
```

### 🪄 Recover a Deleted Branch:

#### Step 1: View Your History

```bash
git reflog
```

Find the commit hash where the branch was deleted.

#### Step 2: Restore It

```bash
git checkout -b <branch-name> <commit-id>
```

---

## ✅ Bonus Tips

* Use `git status` frequently — it shows exactly what's staged, unstaged, or uncommitted.
    
* Use `git log --oneline` for a compact view of your commit history.
    
* If you mess up, try:
    
    ```bash
    git reflog
    ```
    
    to go back in time and undo mistakes.
    

### 🙌 Thank You!

Thank you for taking the time to read this blog.  
If you found it helpful, consider sharing it with your peers or bookmarking it for future reference.  
Keep scripting, keep automating — and keep learning! 💻🚀
