힘내 푸시 오류 : 체크 아웃 분기 업데이트 거부
일부 병합 충돌을 해결하고 커밋 한 후 변경 사항을 푸시하려고 시도하고 다음 오류가 발생했습니다.
c:\Program Files (x86)\Git\bin\git.exe push --recurse-submodules=check "origin" master:master
Done
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To C:/Development/GIT_Repo/Project
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:/Development/GIT_Repo/Project'
누구 든지이 오류의 원인을 알고 있습니까?
베어 및 비 베어 의 두 가지 유형의 리포지토리가 있습니다.
베어 리포지토리에는 작업중인 사본이 없으며 해당 저장소로 푸시 할 수 있습니다. 이것들은 Github에서 얻는 리포지토리 유형입니다! Bare 저장소를 작성하려면 다음을 사용할 수 있습니다.
git init --bare
요컨대, 베어가 아닌 저장소로 푸시 할 수 없습니다(편집 : 글쎄, 현재 체크 아웃 된 리포지토리의 분기로 푸시 할 수 없습니다. 베어 리포지토리를 사용하면 체크 아웃되지 않은 분기로 푸시 할 수 있습니다. 가능하지만 비 베어 리포지토리로 푸시하는 것은 일반적이지 않습니다) . 당신이 할 수있는 일은 다른 저장소에서 가져오고 병합하는 것입니다. 이것이 pull request
Github에서 볼 수있는 방식입니다. 당신은 그들에게서 당신을 끌어 당기라고 요구하고, 당신은 그들에게 억지로 밀어 넣지 않습니다.
업데이트 : 최신 git 버전 (현재 2.3.0)에서 VonC 덕분에 비 베어 리포지토리의 체크 아웃 된 분기로 푸시 할 수 있습니다 . 그럼에도 불구하고 여전히 더러운 작업 트리로 밀 수 는 없습니다. 어쨌든 안전한 작업은 아닙니다.
나는 원격에 체크 아웃 된 것이 (실제로되어 있지 않은) 것을 확인한 다음 맨손으로 확인 하여이 문제를 해결했습니다.
$ git config --bool core.bare true
그 후 git push는 정상적으로 작동했습니다.
요약
데이터 및 기록 손실로 끝날 수있는 방식으로 해당 리포지토리의 사용자를 망칠 수 있으므로 리포지토리의 체크 아웃 된 분기로 푸시 할 수 없습니다 . 그러나 동일한 저장소의 다른 지점으로 푸시 할 수 있습니다.
베어 리포지토리에는 분기가 체크 아웃되지 않으므로 항상 베어 리포지토리의 모든 분기로 푸시 할 수 있습니다.
문제 부검
지점이 체크 아웃되면 커밋은 현재 브랜치의 헤드를 부모로하여 새로운 커밋을 추가하고 브랜치의 헤드를 새로운 커밋으로 이동시킵니다.
그래서
A ← B
↑
[HEAD,branch1]
된다
A ← B ← C
↑
[HEAD,branch1]
그러나 누군가가 그 사이에서 그 지점으로 밀 수 있다면, 사용자는 git 호출 분리 헤드 모드 에 도달 할 것입니다 :
A ← B ← X
↑ ↑
[HEAD] [branch1]
이제 사용자는 다른 지점을 명시 적으로 체크 아웃하지 않아도 더 이상 branch1에 없습니다. 더 나쁜 것은 사용자가 이제 지점 외부 에 있으며 새로운 커밋이 매달려 있다는 것입니다 .
[HEAD]
↓
C
↙
A ← B ← X
↑
[branch1]
이 시점에서 사용자가 다른 지점을 체크 아웃하면이 매달려있는 커밋은 Git의 가비지 수집기에 대한 공정한 게임이됩니다 .
원격 컴퓨터에서 푸시하려는 repo / 디렉토리로 cd하고
$ git config core.bare true
나를 위해 다음과 같은 트릭을 수행했습니다.
git config --global receive.denyCurrentBranch updateInstead
I set up drive F:, almost in its entirety, to sync between my Windows 10 desktop and my Windows 10 laptop, using Git. I ended up running the above command on both machines.
First I shared the desktop's F drive on the network. Then I was able to clone it on my laptop by running:
F: git clone 'file://///DESKTOP-PC/f'
Unfortunately, all the files ended up under "F:\f\" on my laptop, not under F:\ directly. But I was able to cut and paste them manually. Git still worked from the new location afterwards.
Then I tried making some changes to files on the laptop, committing them, and pushing them back to the desktop. That didn't work until I ran the git config command mentioned above.
Note that I ran all these commands from within Windows PowerShell, on both machines.
UPDATE: I still had issues pushing changes, in some cases. I finally just started pulling changes instead, by running the following on the computer I want to pull the latest commit(s) to:
git pull --all --prune
As there's already an existing repository, running
git config --bool core.bare true
on the remote repository should suffice
From the core.bare documentation
If true (bare = true), the repository is assumed to be bare with no working directory associated. If this is the case a number of commands that require a working directory will be disabled, such as git-add or git-merge (but you will be able to push to it).
This setting is automatically guessed by git-clone or git-init when the repository is created. By default a repository that ends in "/.git" is assumed to be not bare (bare = false), while all other repositories are assumed to be bare (bare = true).
TLDR
- Pull & push again:
git pull &&& git push
. - Still a problem? Push into different branch:
git push origin master:foo
and merge it on remote repo. - Alternatively force the push by adding
-f
(denyCurrentBranch
needs to be ignored).
Basically the error means that your repository is not up-to-date with the remote code (its index and work tree is inconsistent with what you pushed).
Normally you should pull
first to get the recent changes and push
it again.
If won't help, try pushing into different branch, e.g.:
git push origin master:foo
then merge this branch on the remote repository back with master.
If you changed some past commits intentionally via git rebase
and you want to override repo with your changes, you probably want to force the push by adding -f
/--force
parameter (not recommended if you didn't do rebase
). If still won't work, you need to set receive.denyCurrentBranch
to ignore
on remote as suggested by a git message via:
git config receive.denyCurrentBranch ignore
Maybe your remote repo is in the branch which you want to push. You can try to checkout another branch in your remote machine. I did this, than these error disappeared, and I pushed success to my remote repo. Notice that I use ssh to connect my own server instead of github.com.
I has this error because the git repo was (accidentally) initialised twice on the same location : first as a non-bare repo and shortly after as a bare repo. Because the .git folder remains, git assumes the repository is non-bare. Removing the .git folder and working directory data solved the issue.
참고URL : https://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch
'IT' 카테고리의 다른 글
파이썬의 'in'연산자를 무시 하시겠습니까? (0) | 2020.05.23 |
---|---|
몽구스 _id와 문자열 비교 (0) | 2020.05.23 |
styles.xml의 사용자 정의 속성 (0) | 2020.05.23 |
템플릿에서 모델 인스턴스 필드 이름과 값을 반복 (0) | 2020.05.23 |
인증 기관에 인증서 서명 요청에 어떻게 서명합니까? (0) | 2020.05.23 |