본문으로 건너뛰기

Git Remote 변경 가이드

GitHub 계정명이나 조직명이 변경되면 기존 저장소의 remote URL도 함께 수정해야 합니다. 이 문서에서는 jbcp-ist에서 nanumspace로 변경하는 과정을 안내합니다.

변경이 필요한 상황

  • GitHub 사용자명(username)을 변경한 경우
  • 저장소를 다른 조직(organization)으로 이전한 경우
  • 조직명을 변경한 경우
중요

remote URL을 변경하지 않으면 git pushgit 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