Skip to content

Commit e559ef3

Browse files
committed
Fix git authentication issues
- Add setup script to configure git authentication with GitHub tokens - Document root causes and solutions for git push failures - Fix missing HOME environment variable and credential helper configuration - Enable HTTPS authentication for git operations Resolves issues with 'Permission denied (publickey)' and 'could not read Username' errors when creating and pushing remote branches.
1 parent 406b366 commit e559ef3

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

docs/git-authentication-fix.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Git Authentication Issue Investigation and Fix
2+
3+
## Problem Summary
4+
5+
The issue with creating and pushing remote git branches was caused by missing environment variables and improper git authentication configuration for HTTPS operations.
6+
7+
## Root Causes Identified
8+
9+
1. **Missing HOME Environment Variable**: The `$HOME` environment variable was not set, causing git to fail when trying to access global configuration files.
10+
11+
2. **No Git Credential Helper**: Git was not configured with a credential helper to manage authentication for HTTPS operations.
12+
13+
3. **Missing Git Credentials**: Although the `GH_TOKEN` environment variable was available, git was not configured to use it for authentication.
14+
15+
## Error Messages Encountered
16+
17+
- Initial error reported: `Permission denied (publickey)`
18+
- Actual error during testing: `fatal: could not read Username for 'https://github.com': No such device or address`
19+
- Global config error: `fatal: $HOME not set`
20+
21+
## Investigation Results
22+
23+
### Environment Analysis
24+
25+
- **Current user**: `root`
26+
- **Working directory**: `/roo/repos/Roo-Code`
27+
- **GitHub CLI status**: ✅ Properly authenticated as `roomote-bot`
28+
- **GitHub token**: ✅ Available as `GH_TOKEN` environment variable
29+
- **Git remote configuration**: ✅ Properly configured to use HTTPS (`https://github.com/RooCodeInc/Roo-Code.git`)
30+
31+
### Configuration Issues Found
32+
33+
- `$HOME` environment variable: ❌ Not set
34+
- Git credential helper: ❌ Not configured
35+
- Git credentials file: ❌ Missing
36+
- Global git configuration: ❌ Inaccessible due to missing `$HOME`
37+
38+
## Solution Implemented
39+
40+
### 1. Environment Setup
41+
42+
```bash
43+
export HOME=/root
44+
```
45+
46+
### 2. Git Credential Configuration
47+
48+
```bash
49+
git config --global credential.helper store
50+
```
51+
52+
### 3. GitHub Token Authentication
53+
54+
```bash
55+
echo "https://roomote-bot:$GH_TOKEN@github.com" > ~/.git-credentials
56+
```
57+
58+
### 4. Automated Setup Script
59+
60+
Created `scripts/setup-git-auth.sh` to automate the fix and ensure consistent configuration.
61+
62+
## Testing Results
63+
64+
After implementing the fix:
65+
66+
- ✅ Successfully created a test branch: `test-branch-push-investigation`
67+
- ✅ Successfully pushed the branch to remote repository
68+
- ✅ Git authentication working properly for HTTPS operations
69+
70+
## Recommendations
71+
72+
### Immediate Actions
73+
74+
1. Run the setup script: `./scripts/setup-git-auth.sh`
75+
2. Ensure `$HOME` environment variable is set in your shell profile
76+
3. Verify git operations work as expected
77+
78+
### Long-term Solutions
79+
80+
1. **Environment Configuration**: Ensure `$HOME` is set in system environment or container configuration
81+
2. **Automated Setup**: Include the git authentication setup in deployment/initialization scripts
82+
3. **Documentation**: Keep this documentation updated for future reference
83+
84+
### Prevention
85+
86+
1. Add environment variable checks to CI/CD pipelines
87+
2. Include git authentication verification in health checks
88+
3. Document required environment variables for development setup
89+
90+
## Usage
91+
92+
To fix git authentication issues, run:
93+
94+
```bash
95+
./scripts/setup-git-auth.sh
96+
```
97+
98+
This script will:
99+
100+
- Set the `$HOME` environment variable if missing
101+
- Configure git credential helper
102+
- Set up GitHub token authentication
103+
- Test the configuration
104+
- Provide clear feedback on the setup status
105+
106+
## Technical Details
107+
108+
### Git Configuration After Fix
109+
110+
- **Credential helper**: `store`
111+
- **Authentication method**: HTTPS with token
112+
- **Credentials location**: `~/.git-credentials`
113+
- **Remote URL**: `https://github.com/RooCodeInc/Roo-Code.git`
114+
115+
### Environment Variables Required
116+
117+
- `GH_TOKEN`: GitHub personal access token
118+
- `HOME`: User home directory path (set to `/root`)
119+
120+
## Troubleshooting
121+
122+
If you encounter similar issues in the future:
123+
124+
1. Check if `$HOME` is set: `echo $HOME`
125+
2. Verify GitHub token is available: `echo $GH_TOKEN | head -c 10`
126+
3. Check git credential helper: `git config --get credential.helper`
127+
4. Test git authentication: `git ls-remote origin`
128+
5. Run the setup script: `./scripts/setup-git-auth.sh`

scripts/setup-git-auth.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Git Authentication Setup Script
4+
# This script fixes the git authentication issues by setting up proper environment variables
5+
# and git configuration for HTTPS authentication with GitHub tokens.
6+
7+
set -e
8+
9+
echo "Setting up Git authentication..."
10+
11+
# Set HOME environment variable if not set
12+
if [ -z "$HOME" ]; then
13+
export HOME=/root
14+
echo "✓ Set HOME environment variable to /root"
15+
fi
16+
17+
# Ensure the HOME directory exists
18+
mkdir -p "$HOME"
19+
20+
# Configure git credential helper to use stored credentials
21+
git config --global credential.helper store
22+
echo "✓ Configured git credential helper"
23+
24+
# Set up git credentials using the GitHub token
25+
if [ -n "$GH_TOKEN" ]; then
26+
echo "https://roomote-bot:$GH_TOKEN@github.com" > "$HOME/.git-credentials"
27+
echo "✓ Configured GitHub authentication with token"
28+
else
29+
echo "⚠️ Warning: GH_TOKEN environment variable not found"
30+
echo " Please ensure the GitHub token is available as GH_TOKEN"
31+
fi
32+
33+
# Set git user configuration if not already set
34+
if ! git config --global user.name >/dev/null 2>&1; then
35+
git config --global user.name "roomote-bot"
36+
echo "✓ Set git user.name to roomote-bot"
37+
fi
38+
39+
if ! git config --global user.email >/dev/null 2>&1; then
40+
git config --global user.email "[email protected]"
41+
echo "✓ Set git user.email"
42+
fi
43+
44+
# Test git authentication
45+
echo "Testing git authentication..."
46+
if git ls-remote origin >/dev/null 2>&1; then
47+
echo "✅ Git authentication test successful!"
48+
else
49+
echo "❌ Git authentication test failed"
50+
exit 1
51+
fi
52+
53+
echo "Git authentication setup complete!"

0 commit comments

Comments
 (0)