简体   繁体   中英

Can't push to remote repository even though remote is set to bare

I've been searching around to find out how to fix this issue but I can't seem to find anything that works for me. So I thought I'd ask you.

I've recently learned how to use git for source control and decided I wanted to start using it for a website I had already built. The server I have the website on (Not my own. Buying server space from arvixe) already had git installed. I started setting up by going to my home folder (via ssh) and running

git init

I then wanted to add all the files I already had in the folder to git so I ran:

git add .

and then to commit them:

git commit .

I wanted to be able to push to the server from my laptop so I did this to get a bare repository:

git init --bare

(I did this after googling the issue and finding that it worked in other cases. Before this I tried checking out a dummy branch via ssh but when I did this nothing I pushed from my laptop to the server actually changed anything.)

After this I cloned the repository on to my laptop via ssh and sourcetree. When I make changes on my laptop and try to push them to the remote repo I get this error message:

stdin: is not a tty

/etc/bashrc: line 100: $HISTFILE: ambiguous redirect

remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K

remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To ssh://ihlenfmt@laurieihlenfield.com/home/ihlenfmt

 ! [remote rejected] master -> master (branch is currently checked out)

I'm very new to git so it's highly likely I've done something stupid. Anyone see where I've gone wrong?

The problem: You want to push the contents to a non-bare server repo (which has files checked-out as workign copy). Technically this is possible but this is not a "normal" setup. I will give you a "fix" for your current situation first: Either:

a) on your server, initialize git repo as 'bare', ie

git config core.bare true

This way, you can access this from other machines using one of the allowed git protocols (including ssh).

OR b) on the server machine:

git config receive.denyCurrentBranch ignore

OR (git v2.3+) c)

git config --local receive.denyCurrentBranch updateInstead

Keep in mind, the above options will cause you problems down the road when you push from your laptop and commit on the server concurrently.

A better solution is to create a separate git repo elsewhere (even on the same server) which can be accessed by your web server account and laptop. Then clone this repo in your webserver and the laptop. Example:

</home/user/some-dir-accessible-via-ssh>$ git init . --bare
</your-webserver-root>$ git init . #(not bare)
</your-webserver-root>$ git commit #(etc)
</your-webserver-root>$ git push </home/user/some-dir-accessible-via-ssh> master

If all works,

</your-webserver-root>$ git remote add origin </home/user/some-dir-accessible-via-ssh>

On laptop

$git clone <ssh://user@serverip/home/user/some-dir-accessible-via-ssh>

Your workflow would be like this:

  • Work on your laptop, pull, then push to server.
  • goto sever, pull from the origin
  • make changes on the server. push to origin
  • etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM