DamDamich
@DamDamich
Network Engineer

Ошибка при git push?

Добрый день,
При создании локального git хранилища, столкнулся со следующей проблемой.
[git@su-git-01 testdir]$ git init
Initialized empty Git repository in /git/testdir/.git/
[git@su-git-01 testdir]$ touch test.txt && echo "HELLO" >> test.txt
[git@su-git-01 testdir]$ git add test.txt
[git@su-git-01 testdir]$ git commit -m "First Init"
[master (root-commit) d6825e1] First Init
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
[git@su-git-01 testdir]$

На клиенте делаю следующие шаги:
$ git clone ssh://git@172.24.4.100:/git/testdir
Cloning into 'testdir'...
git@172.24.4.100's password:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

$ echo "WORL" >> test.txt
$ git commit -m "Second Init"
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
        modified:   test.txt

no changes added to commit
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean
$ git push origin master
git@172.24.4.100's password:
Counting objects: 5, done.
Writing objects: 100% (3/3), 263 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
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 ssh://git@172.24.4.100:/git/testdir
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://git@172.24.4.100:/git/testdir'

Соответственно, после git reset --hard, ошибка остается прежней.
Впервые столкнулся с git, прошу совета, что я делаю не так?
  • Вопрос задан
  • 17274 просмотра
Решения вопроса 2
v_decadence
@v_decadence
Ошибка из-за того, что Git по умолчанию не разрешает обновлять текущую ветку не bare-хранилища посредством push.

На сервере либо инициализируем хранилище так:
git init --bare
Это создаст хранилище без рабочей копии (bare хранилище)

Либо задаём в конфиге хранилища:
[receive]
denyCurrentBranch = ignore (или warn)
Чтобы можно было пушить в текущую ветку не bare хранилища.

Второй способ не рекомендуется, так как может привести к конфликтному состоянию рабочей копии.

Если на сервере должна быть рабочая копия, то только второй способ либо сделать bare-хранилище, куда пушить с клиента (оно будет точкой синхронизации), а в месте, где нужна рабочая копия, склонировать первое хранилище и периодически из него делать pull.

Bare-хранилище
Ответ написан
@DevOpsEngineer
Linux/network/devops инженер.
иногда проще использовать

server$ git checkout --detach
laptop$ git push master
servet$ git stash
server$ git checkout master


Если вы понимаете что такое DETACHED HEAD
https://git-scm.com/docs/git-checkout/
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы