Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.
I am now
Check your .git/config
in the destination project:
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[receive]
denyCurrentBranch = updateInstead
If the core. bare
is false, you can set it to true:
$ git config core.bare true
and then in your local push to remote:
git push remote_repo // suppose the destination repo is remote_repo
it will success, in the remote_repo you can check git version.
$ git log -1
commit 0623b1b900ef7331b9184722a5381bbdd2d935ba
Author: aircraft < aircraft_xxx@126.com>
Date: Thu May 17 21:54:37 2018 +0800
and now you can not use git in your "workspace":
$ git status
fatal: This operation must be run in a work tree
you should set bare.bare
back to false.
$ git config core.bare false
You can recreate your server repository and push from your local branch master to the server master.
mkdir myrepo.git
cd myrepo.git
git init --bare
git push origin master:master
In fact, set the remote to a non-checked out branch is sufficient. After you checked out your remote in a different branch, you can push.
I had the same issue. For me, I use Git push to move code to my servers. I never change the code on the server side, so this is safe.
In the repository, you are pushing to type:
git config receive.denyCurrentBranch ignore
This will allow you to change the repository while it's a working copy.
After you run a Git push, go to the remote machine and type this:
git checkout -f
This will make the changes you pushed be reflected in the working copy of the remote machine.
Please note, this isn't always safe if you make changes on in the working copy that you're pushing to.
I had the same problem using Git to synchronise repositories on my Android phone and laptop. The solution for me was to do a pull instead of a push, as @CharlesBailey suggested.
git push origin master
on the Android repository fails for me with the same error messages that @hap497 got because of a push to a nonbare checkout of a repository + working-copy.
git pull droid master
on the laptop repository and working-copy works for me. Of course, you need to have previously run something like git remote add droid /media/KINGSTON4GB/notes_repo/
.
My solution (in use)
bingo