programing

git push : refs / heads / my / subbranch exists, cannot create

copysource 2021. 1. 16. 20:37
반응형

git push : refs / heads / my / subbranch exists, cannot create


서버의 저장소에 somme 하위 폴더를 만들 수 없습니까?

만약 내가한다면:

git push origin dev/master 

모든 일을 찾아

하지만 내가하면

git push origin dev/sub/master

알 겠어:

error: 'refs/heads/dev/sub' exists; cannot create 'refs/heads/dev/sub/master'

"git branch -r"로 확인하고 ssh로 직접 확인했는데 이미 만들어진 dev / sub 폴더가 없습니다.

뭐가 문제 야?


존재 하는 폴더 가 아니라 브랜치 입니다. (음, 어딘가에 폴더 / 디렉토리가 관련되어있을 수도 있고, 참조가 "포장"되어 디렉토리 내의 파일로 존재하는 것을 중지하기 때문에 아닐 수도 있습니다.)

  • 분기 b가있는 경우 명명 된 분기를 b/anything만들 수 없습니다 .
  • 마찬가지로 분기 dev/b가 존재 하면 dev/b/c생성 할 수 없습니다.

이것은 git 내부 제한입니다. 이 특별한 경우에 remote origin에는 이름이 지정된 브랜치가 있습니다 dev/sub(사용 여부에 관계없이 중요한 것은 원격에 있는지 여부입니다). 에서 origin라는 분기 를 만들려면 dev/sub/master먼저 dev/subon 이라는 분기를 삭제해야합니다 origin.

git push origin :dev/sub

(물론,이 지점을 삭제하면 그래서 당신이 당신이 무엇을하고 있는지 알고있을, 거기 중요한 무언가를 삭제할 수 있습니다. 일반적으로, 당신이 할 수 있습니다 git fetch origin첫째, 캡처 자신의 dev/suborigin/dev/sub. 그런 다음라는 로컬 브랜치 할 수 dev/renamed-sub같은 커밋을 가리키는를 , dev/renamed-sub원격 에서 생성 , 원격 삭제 dev/sub원격 에서 생성 dev/sub/master.)


원격지 ( origin호스팅되는 시스템)에 로그인 할 수있는 경우 저기 저장소로 이동하여 로컬 dev/sub브랜치의 이름을 바꿀 수 있습니다. (아래의 설명에 따르면 자동 배포 스크립트가 고장난 것 같습니다.이 스크립트는 푸시되는 모든 것이 아닌 "배포 가능한"브랜치 만 배포하도록 수정해야합니다.하지만 여기서 추측하고 있습니다.)


내 저장소에 체크 아웃하지 않은 존재하지 않는 원격 브랜치에 대한 정보가 있기 때문에 가져올 수없는 상태였습니다. 나는 다음 조합 (@torek에게 감사)을 실행하여 해결했습니다.

  • git branch -r 원격 지점의 로컬 사본 나열
  • git ls-remote 원격 지점 나열
  • git fetch --prune origin원격 지점의 로컬 사본을 업데이트하십시오 ( 실제로 도움이되지 않았습니다 )
  • git remote prune origin제거 원격 지점에 대한 정보를 제거 ( 이했다 )

나를 위해->

오류 =

fatal: cannot lock ref 'refs/heads/release/wl/2.3': 'refs/heads/release/wl' 
exists; cannot create 'refs/heads/release/wl/2.3'

솔루션 =

$~ git update-ref -d refs/heads/release/wl
$~ git checkout release/wl/2.3

현재 허용 대답은 내가 삭제 원격 REPO에 심판을 가지고 있지 않았기 때문에 나에게 도움이되지 않았다 - 내 지역에 순수했다! 따라서 이러한 상황에 처한 경우 수행 할 작업은 다음과 같습니다.

이것이 내가 직면 한 문제입니다.

$ git fetch origin
error: cannot lock ref 'refs/remotes/origin/fix/sub-branch': 
'refs/remotes/origin/fix' exists; cannot create 
'refs/remotes/origin/fix/sub-branch'
From <repo URL>
 ! [new branch]      fix/sub-branch          -> origin/fix/sub-branch
 (unable to update local ref)

나는 받아 들여진 대답의 제안을 시도했지만 이것을 얻었습니다.

$ git push origin :fix
error: unable to delete 'fix': remote ref does not exist
error: failed to push some refs to <repo URL>

그래서 심판은 심지어 존재하지도 않았습니다 origin-그것은 분명히 내 로컬 저장소 어딘가에 어딘가에 매달려있었습니다. 그래서 나는 다음 $ git remote show me을 생산했습니다.

Remote branches:
...
refs/remotes/origin/fix             stale (use 'git remote prune' to remove)
...

그런 다음 솔루션을 명확하게 만들었습니다.

$ git remote prune origin
Pruning origin
URL: <redacted>
 * [pruned] origin/fix

이것으로 문제가 사라졌습니다.

$ git fetch origin
remote: Counting objects: 5, done.
remote: Total 5 (delta 2), reused 2 (delta 2), pack-reused 3
Unpacking objects: 100% (5/5), done.
From <repo URL>
 * [new branch]      fix/sub-branch          -> origin/fix/sub-branch

이 명령을 사용하여 수정하십시오.

git gc

현재 저장소 내에서 여러 하우스 키핑 작업을 실행하고 연결할 수없는 개체를 제거합니다 ( git prune을 호출 하여 git fsck --unreachable).

더 읽어보기 : git help gc그리고git help prune


#!/usr/bin/env bash
echo "update-ref delete refs/tags"
log="git-update-ref-errors.log"
script="./git-update-ref-exist-tags-delete.sh"
git_command="git update-ref -d refs/tags"

echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors to ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}

echo fetch
log="git-fetch-errors.log"
script="./git-fetch-exist-tags-delete.sh"
git_command="git fetch"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
git fetch

echo pull
log="git-pull-errors.log"
script="./git-pull-exist-tags-delete.sh"
git_command="git pull"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
git pull

echo push
log="git-push-errors.log"
script="./git-push-exist-tags-delete.sh"
git_command="git push"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
git push

위의 스크립트는 XXX-errors.log에 오류를 기록하고 다음 명령을 사용하여 XXX-errors.log에서 XXX-exist-tags-delete.sh를 자동으로 생성하고 실행하여 오류를 수정합니다.

  1. git update-ref -d refs / tags
  2. 자식 가져 오기
  3. git pull
  4. git push

git remote prune origin 나를 위해 문제를 해결했습니다.


Windows 사용자로서 지금까지 어떤 솔루션도 문제를 해결하지 못했습니다. 이 오류가 발생한 이유는 (OP의 분기 이름을 사용하여) 분기를 만들려고 dev/sub했지만 다른 사람이 분기를 만들었고 Dev우리 모두 알고 있듯이 창에는 대소 문자를 구분하지 않는 파일 시스템이 있기 때문입니다.

따라서 Windows가 아래로 내려 가려고 할 때 dev/sub먼저 폴더를 만들려고 dev했지만 Dev이미 존재 했기 때문에 할 수 없었습니다 .

The solution was to delete the Dev branch locally and remotely with git branch -d Dev && git push origin :Dev. A git pull after this ran fine.

Another lesson going forward, branch names should always be lowercase to avoid this kind of gotcha's.


If all else fails, check that your repo system does not have limitations for branch names. In my case, you could only create branches that start with SD-<number>. Any other naming would give you just a generic:

remote: error: cannot lock ref 'refs/heads/mybranch': 'refs/heads/mybranch/environment-variables' exists; cannot create 'refs/heads/mybranch'
To git.example.com:project/repository.git
 ! [remote rejected] mybranch -> mybranch (failed to update ref)
error: failed to push some refs to 'git@git.example.com:project/repository.git'

ReferenceURL : https://stackoverflow.com/questions/22630404/git-push-refs-heads-my-subbranch-exists-cannot-create

반응형