Github Repository 및 인증 재설정 문제해결

엔케이·2025년 1월 21일
post-thumbnail

Git 문제 해결 정리

Git을 사용하면서 발생한 문제와 해결 방법을 정리합니다. 아래는 실제 발생했던 상황과 이를 해결하기 위한 단계별 과정입니다.


1. GitHub 로그인 정보 변경 및 Repository 재설정

문제 상황

  • GitHub에서 기존 계정과 연결된 상태에서 새 계정으로 작업하려고 하니 접근 권한이 거부됨.
  • 에러 메시지:
    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

해결 방법

  1. 기존 자격 증명 삭제

    • Windows:
      • 제어판 > 사용자 계정 > 자격 증명 관리자 > Windows 자격 증명에서 github.com 항목 삭제.
    • macOS:
      • 키체인 접근에서 github.com 관련 항목 삭제.
    • Linux:
      • ~/.git-credentials 파일 열기:
        nano ~/.git-credentials
        https://previous-project:<token>@github.com 삭제 후 저장.
  2. 새 자격 증명 추가

    • GitHub Personal Access Token(PAT) 생성: GitHub Token 생성 페이지
    • 새 토큰을 저장하고 터미널에서 새 작업을 시도하여 사용자명과 토큰 입력.
  3. Repository URL 재설정

    git remote set-url origin https://github.com/current-project.git

    URL 변경 후 확인:

    git remote -v

2. Git Push 시 에러 (non-fast-forward)

문제 상황

  • 로컬 브랜치에서 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.

해결 방법

  1. 원격 브랜치와 동기화

    git pull origin main
    • 충돌 발생 시:
      1. 충돌 파일 확인 후 수정.
      2. 수정된 파일 스테이징:
        git add <파일명>
      3. 커밋:
        git commit
  2. 푸시 재시도

    git push origin main
  3. Force Push가 필요한 경우 (주의!)

    • 로컬 변경사항을 강제로 원격에 덮어씌우기:
      git push --force origin main
    • ⚠️ Force Push는 협업 프로젝트에서 신중히 사용.

3. Git 설정 (user.name & user.email)

설정 방법

  1. Global 설정 (모든 Repository에 적용):

    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
  2. Local 설정 (특정 Repository에만 적용):

    git config user.name "Your Name"
    git config user.email "your.email@example.com"
  3. 설정 확인:

    • Global 설정 확인:
      git config --global --list
    • Local 설정 확인:
      git config --list
  4. 설정 삭제:

    • Global 설정 삭제:
      git config --global --unset user.name
      git config --global --unset user.email
    • Local 설정 삭제:
      git config --unset user.name
      git config --unset user.email

결론

위 단계를 통해 GitHub 인증 문제 및 푸시 충돌 문제를 해결할 수 있었습니다. Git 사용 중 발생하는 에러는 차근차근 문제를 분석하고 해결하는 것이 중요합니다. 필요시 추가 명령어와 설정을 검토하세요!

profile
FE 개발자

0개의 댓글