Real-world Git errors and how heal helps fix them.
$ git merge feature-branch
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.$ git merge feature-branch 2>&1 | healGit encountered conflicts while merging that need manual resolution.
**Solution:**
1. View conflicted files:
```bash
git status
-
Open the conflicted file and look for conflict markers:
<<<<<<< HEAD your changes ======= their changes >>>>>>> feature-branch -
Resolve conflicts manually, then:
git add src/app.js git commit -m "Merge feature-branch, resolved conflicts" -
Or abort the merge:
git merge --abort
-
Use a merge tool:
git mergetool
### Error
```bash
$ git push origin main
To github.com:user/repo.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
$ git push origin main 2>&1 | healYour local branch is behind the remote branch. Someone else pushed changes.
**Solution:**
1. **Recommended**: Pull and merge first:
```bash
git pull origin main
# Resolve any conflicts if they occur
git push origin main
-
Pull with rebase (cleaner history):
git pull --rebase origin main git push origin main
-
Force push (DANGEROUS - only if you're sure):
git push --force origin main # or safer: git push --force-with-lease origin main -
Check what's different:
git fetch origin git log HEAD..origin/main
### Error
```bash
$ git push origin main
remote: Support for password authentication was removed on August 13, 2021.
remote: Please use a personal access token instead.
fatal: Authentication failed for 'https://github.com/user/repo.git/'
$ git push origin main 2>&1 | healGitHub no longer accepts password authentication. You need a Personal Access Token (PAT).
**Solution:**
1. Create a Personal Access Token on GitHub:
- Go to Settings → Developer settings → Personal access tokens
- Generate new token with 'repo' scope
- Copy the token
2. Use the token as password when prompted, or configure it:
```bash
git remote set-url origin https://YOUR_TOKEN@github.com/user/repo.git
-
Better: Use SSH instead:
# Generate SSH key if you don't have one ssh-keygen -t ed25519 -C "your_email@example.com" # Add to GitHub: Settings → SSH and GPG keys cat ~/.ssh/id_ed25519.pub # Change remote to SSH git remote set-url origin git@github.com:user/repo.git
-
Use Git Credential Manager:
git config --global credential.helper store
### Error
```bash
$ git checkout abc123
Note: switching to 'abc123'.
You are in 'detached HEAD' state...
$ git status 2>&1 | healYou're in detached HEAD state - not on any branch.
**Solution:**
1. If you want to keep changes, create a new branch:
```bash
git checkout -b new-branch-name
-
Return to a branch without keeping changes:
git checkout main
-
If you made commits in detached HEAD:
# Note the commit hash git log # Switch to a branch git checkout main # Cherry-pick your commits git cherry-pick <commit-hash>
-
Or merge the detached HEAD commits:
git branch temp-branch git checkout main git merge temp-branch
### Error
```bash
$ git pull origin main
error: Your local changes to the following files would be overwritten by merge:
src/config.js
Please commit your changes or stash them before you merge.
Aborting
$ git pull origin main 2>&1 | healYou have uncommitted changes that conflict with incoming changes.
**Solution (choose one):**
1. Stash your changes temporarily:
```bash
git stash
git pull origin main
git stash pop
-
Commit your changes first:
git add . git commit -m "WIP: save current work" git pull origin main
-
Discard your local changes (careful!):
git checkout -- src/config.js git pull origin main
-
Pull with rebase and autostash:
git pull --rebase --autostash origin main
### Error
```bash
$ git push origin main
remote: error: GH001: Large files detected. You may want to try Git Large File Storage
remote: error: File large-file.zip is 150.00 MB; this exceeds GitHub's file size limit of 100.00 MB
$ git push origin main 2>&1 | healYou're trying to push a file larger than GitHub's 100MB limit.
**Solution:**
1. Remove the file from Git history:
```bash
git rm --cached large-file.zip
git commit --amend -m "Remove large file"
git push origin main
-
Use Git LFS for large files:
# Install Git LFS git lfs install # Track large files git lfs track "*.zip" git add .gitattributes git add large-file.zip git commit -m "Add large file with LFS" git push origin main
-
Add to .gitignore if it shouldn't be tracked:
echo "large-file.zip" >> .gitignore git rm --cached large-file.zip git commit -m "Remove large file from tracking"
-
If already in history, use BFG Repo-Cleaner:
bfg --delete-files large-file.zip git reflog expire --expire=now --all git gc --prune=now --aggressive
### Error
```bash
$ git rebase main
CONFLICT (content): Merge conflict in src/app.js
error: could not apply abc123... Add new feature
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
$ git rebase main 2>&1 | healGit encountered conflicts during rebase that need manual resolution.
**Solution:**
1. View conflicted files:
```bash
git status
-
Resolve conflicts in the files, then:
git add src/app.js git rebase --continue
-
Skip the problematic commit:
git rebase --skip
-
Abort the rebase:
git rebase --abort
-
Use a merge tool:
git mergetool git rebase --continue
### Error
```bash
$ git checkout -b feature-branch
fatal: A branch named 'feature-branch' already exists.
$ git checkout -b feature-branch 2>&1 | healA branch with that name already exists locally.
**Solution:**
1. Switch to the existing branch:
```bash
git checkout feature-branch
-
Delete the old branch and create new:
git branch -D feature-branch git checkout -b feature-branch
-
Create a branch with a different name:
git checkout -b feature-branch-v2
-
Check all branches:
git branch -a