Git을 사용하면서 발생한 문제와 해결 방법을 정리합니다. 아래는 실제 발생했던 상황과 이를 해결하기 위한 단계별 과정입니다.
remote: Permission to current-project.git denied to previous-project.
fatal: unable to access 'https://github.com/current-project.git/': The requested URL returned error: 403기존 자격 증명 삭제
github.com 항목 삭제.키체인 접근에서 github.com 관련 항목 삭제.~/.git-credentials 파일 열기:nano ~/.git-credentialshttps://previous-project:<token>@github.com 삭제 후 저장.새 자격 증명 추가
Repository URL 재설정
git remote set-url origin https://github.com/current-project.git
URL 변경 후 확인:
git remote -v
git push를 실행했더니 원격 브랜치와 충돌이 발생.! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/current-project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.원격 브랜치와 동기화
git pull origin main
git add <파일명>git commit푸시 재시도
git push origin main
Force Push가 필요한 경우 (주의!)
git push --force origin mainGlobal 설정 (모든 Repository에 적용):
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Local 설정 (특정 Repository에만 적용):
git config user.name "Your Name"
git config user.email "your.email@example.com"
설정 확인:
git config --global --listgit config --list설정 삭제:
git config --global --unset user.name
git config --global --unset user.emailgit config --unset user.name
git config --unset user.email위 단계를 통해 GitHub 인증 문제 및 푸시 충돌 문제를 해결할 수 있었습니다. Git 사용 중 발생하는 에러는 차근차근 문제를 분석하고 해결하는 것이 중요합니다. 필요시 추가 명령어와 설정을 검토하세요!