0

I’ve ...

  • created a new repo,
  • added submodule
  • made changes in submodule ...
git init
git submodule add ../../origin/subpr1/
cd subpr1/
touch hello.txt
git add hello.txt
git commit -m "hello.txt"

... and now I’m trying to push these changes to the.

$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 240 bytes | 240.00 KiB/s, done.
Total 2 (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: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To C:/src/lab/Git/mulliple_git/origin/subpr1
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/src/lab/git/origin/subpr1'

What step did I miss? Here are some advises I was given by git. But what should I do in my case?

zhekaus
  • 3,126
  • 6
  • 23
  • 46
  • 1
    Does this answer your question? [Git push error '\[remote rejected\] master -> master (branch is currently checked out)'](https://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked) – phd Dec 17 '19 at 09:29
  • https://stackoverflow.com/search?q=%5Bgit%5D+remote%3A+error%3A+refusing+to+update+checked+out+branch – phd Dec 17 '19 at 09:29

1 Answers1

0

Your submodule seems to point to a local directory that by itself is a (non-bare) Git repository / working tree. Like the error messages explains, pushing is denied by default in such a case to avoid inconsistencies with the submodule's own working tree meta-data. Usually, submodules point to remote (and bare) repositories to avoid such issues. I.e., you should have added the remote URL of your working tree at /src/lab/git/origin/subpr1 as the submodule, not the /src/lab/git/origin/subpr1 directory itself.

sschuberth
  • 28,386
  • 6
  • 101
  • 146
  • Oops. I was thinking that when I clone anything it become bare to new copy. – zhekaus Dec 17 '19 at 08:50
  • Nope, the default `clone` creates a non-bare working tree to work with the remote, unless you [pass](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---bare) `--bare` to `git clone`. – sschuberth Dec 17 '19 at 10:03