Git Remote 변경 가이드
변경 배경
회사 GitHub 조직 도메인이 jbcp-ist에서 nanumspace로 변경되었습니다. 이에 따라 모든 저장소의 remote URL을 새 조직 도메인에 맞게 업데이트해야 합니다.
:::info 참고 GitHub는 조직명 변경 시 기존 URL에서 자동 리다이렉트를 제공하지만, 영구적으로 보장되지 않으므로 가능한 빨리 remote URL을 변경하는 것을 권장합니다. :::
:::danger 중요
remote URL을 변경하지 않으면 리다이렉트가 만료된 후 git push와 git pull이 실패합니다.
:::
현재 remote 확인
먼저 현재 설정된 remote URL을 확인합니다.
git remote -v
변경 전 출력 예시:
origin https://github.com/jbcp-ist/my-project.git (fetch)
origin https://github.com/jbcp-ist/my-project.git (push)
Remote URL 변경
HTTPS 방식
git remote set-url origin https://github.com/nanumspace/my-project.git
SSH 방식
git remote set-url origin git@github.com:nanumspace/my-project.git
변경 확인
URL이 올바르게 변경되었는지 확인합니다.
git remote -v
변경 후 출력 예시:
origin https://github.com/nanumspace/my-project.git (fetch)
origin https://github.com/nanumspace/my-project.git (push)
연결 테스트
변경 후 정상적으로 통신되는지 확인합니다.
# 원격 저장소 정보 가져오기
git fetch origin
# 또는 pull 테스트
git pull
오류 없이 완료되면 변경이 성공한 것입니다.
여러 저장소 일괄 변경
프로젝트가 여러 개인 경우 아래 스크립트로 일괄 변경할 수 있습니다.
Bash (Linux/macOS/Git Bash)
# 저장소들이 있는 상위 디렉토리에서 실행
for dir in */; do
if [ -d "$dir/.git" ]; then
echo "변경 중: $dir"
cd "$dir"
git remote set-url origin "$(git remote get-url origin | sed 's/jbcp-ist/nanumspace/g')"
git remote -v
cd ..
fi
done
PowerShell (Windows)
Get-ChildItem -Directory | ForEach-Object {
if (Test-Path "$($_.FullName)\.git") {
Write-Host "변경 중: $($_.Name)"
Set-Location $_.FullName
$url = git remote get-url origin
$newUrl = $url -replace 'jbcp-ist', 'nanumspace'
git remote set-url origin $newUrl
git remote -v
Set-Location ..
}
}
요약
| 단계 | 명령어 |
|---|---|
| 현재 URL 확인 | git remote -v |
| URL 변경 (HTTPS) | git remote set-url origin https://github.com/nanumspace/저장소명.git |
| URL 변경 (SSH) | git remote set-url origin git@github.com:nanumspace/저장소명.git |
| 변경 확인 | git remote -v |
| 연결 테스트 | git fetch origin |