0

My local repository is on master branch. I've created empty remote repository and add it.

git remote -v
origin  git@100.100.100.100:test-repo.git (fetch)
origin  git@100.100.100.100:test-repo.git (push)

Now I want to push my work to remote server, but I have error

git push -u origin master

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 221 bytes | 221.00 KiB/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: 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 100.100.100.100:test-repo.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git@100.100.100.100:test-repo.git'

I can't do it for master branch. But when I did it for another branch it works:

git checkout -b test_branch1

Switched to a new branch 'test_branch1'

git push -u origin test_branch1

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 221 bytes | 221.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 100.100.100.100:test-repo.git
 * [new branch]      test_branch1 -> test_branch1
Branch 'test_branch1' set up to track remote branch 'test_branch1' from 'origin'.
denis
  • 77
  • 6
  • 1
    The remote isn't a bare repo. Why is that? – evolutionxbox Jul 14 '22 at 11:02
  • What do you mean with "bare repo"? – denis Jul 14 '22 at 11:07
  • 1
    A [bare repo](https://stackoverflow.com/a/49335973/212858) is one with no working tree. Upstream server repos, where you're not working on the local tree anyway, do not need one, and in fact having it only causes problems. This is described in the [manual](https://git-scm.com/docs/git-clone), and mentioned in the free online book chapter on [Getting Git on a Server](https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server) – Useless Jul 14 '22 at 11:18
  • https://stackoverflow.com/search?q=%5Bgit%5D+remote%3A+error%3A+refusing+to+update+checked+out+branch – phd Jul 14 '22 at 11:18

1 Answers1

0

use git --bare init, instead of git init

  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Jul 15 '22 at 01:11