I am a git newbie and I am attempting a minimal clone experiment on my personal hard drive.
I am on Windows 11, using Git Bash.
I have set up a batch file called ‘setup.bat’. The code of this batch file is shown below:
echo "Minimal git clone exercise."
rm -r -d -f toy_repo the_clone
ls -l -a
mkdir toy_repo
cd toy_repo
git init
touch file01.txt
git add file01.txt
git commit -a -m "Made empty file: file01.txt"
ls -l -a
cd ..
git clone toy_repo the_clone
cd the_clone
ls -l -a
git log
touch file02.txt
git add file02.txt
git commit -a -m "Made empty file: file02.txt"
ls -l -a
git log
git status
git push
When ‘git status’ is called I am invited to ‘git push’ as follows:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
When I (the batch file) enters ‘git push’ the following messy error messages are generated. What am I doing wrong?
nothing to commit, working tree clean
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 247 bytes | 247.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 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:/temp/git_play/toy_repo
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:/temp/git_play/toy_repo'
What part of the message is unclear to you exactly? You’re trying to update (through push) the currently checked out branch of your toy_repo. This is disabled by default on non-bare repos to avoid inconsistencies. Try to push to another branch with something along the lines of
git push origin master:test-branch
(or, alternatively, checkout a different branch on toy_repo before you retry your initial push).@RomainValeri Is there a way for me, from within the_clone, to bring toy_repo into conformity with the_clone?
@Argent You shouldn’t push into non-bare repository, only pull into it. So for “Is there a way for me, from within the_clone, to bring toy_repo into conformity with the_clone?” the answer is No! Either you do
cd ../toy_repo && git pull ../the_clone
or you converttoy_repo
to a bare repo (or recreate your example from the very beginning initializingtoy_repo
as a bare from the very beginning).If error messages are short, people don’t understand it; if error messages are long, people get overwhelmed and won’t read it