Git Push Error'[[Remote Deny] Host - > Host (Branch currently checked out)''

Keywords: git ssh Android

Yesterday, I published a post about how to Git Repository from one of my computers Problem cloning to another computerHow do I "git clone" from another computer? .

Now I can successfully clone the Git repository from the source (192.168.1.2) to the target (192.168.1.1).

However, when I was on a file, git commit-a-m "test" and git push, I received this error at my destination (192.168.1.1):

git push                                                
hap@192.168.1.2's password: 
Counting objects: 21, done.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1010 bytes, done.
Total 11 (delta 9), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error: 
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error: 
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git+ssh://hap@192.168.1.2/media/LINUXDATA/working
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git+ssh://hap@192.168.1.2/media/LINUXDATA/working'

I'm using two different Git versions (remote version 1.7, local computer version 1.5).Is that possible?

#1st floor

I had the same problem synchronizing the Repositories on my Android phone and laptop with Git.For me, the solution is to pull rather than push as suggested by @Charles Bailey.

The git push origin master on the Android repository failed to me and displayed the same error message as @ hap497 due to bare machine checkouts pushed to the repository + working copy.

The git pull droid master and work-copy on the notebook repository are useful to me.Of course, you need to run git remote add droid/media/KINGSTON4GB/notes_repo/ before.

#2nd floor

You can see how the bare server works through the following tests:

Imagine you have a workstation and a server hosting a real-time site, and you want to update the site from time to time (this also applies when two developers send their work back and forth through a bare intermediary).

Initialization

Create some directories on your local computer and cd into them, then execute the following commands:

# initialization
git init --bare server/.git
git clone server content
git clone server local
  1. First, you create a naked server directory (note the last.git).This directory is used only as a container for repository files.
  2. The server repository is then cloned to the newly created content directory.This is your on-site/production catalog, which will be served by your server software.
  3. The first two directories are on the server, and the third is a local directory on the workstation.

Workflow

Now this is the basic workflow:

  1. Enter a local directory, create some files, and submit.Finally, push them to the server:

    # create crazy stuff git commit -av git push origin master
  2. Now enter the content directory and update the contents of the server:

    git pull
  3. Repeat 1-2.The content here may be another developer who can also be pushed to the server, or a local developer from whom you can get it.

#3rd floor

The best way is to:

mkdir ..../remote
cd ..../remote
git clone --bare .../currentrepo/

This clones the repository, but does not create any working copies at.../remote.If you look at the remote directory, you'll see a directory created called currentrepo.git, which may be what you want.

Then from your local Git repository:

git remote add remoterepo ..../remote/currentrepo.git

After making changes, you can:

git push remoterepo master

#4th floor

I had to rerun git --init in my existing bare warehouse, which already created a.Git directory in the bare warehouse tree - I realized I had to type git status there.I deleted it, everything is fine:)

(All of these answers are good, but for me this is completely different (as far as I know), as described earlier.)

#5th floor

With some setup steps, you can easily deploy changes to your site using a single line

git push production

This is simple, and you don't have to log in to the remote server to perform pulls or anything else.Please note that this will be most effective if you do not use production checkout as a work branch!(OP works in a slightly different context, I think @Robert Gould's solution solves this problem well.This solution is more suitable for deploying to remote servers.)

First, you need to set up a bare warehouse somewhere on a server other than Webroot.

mkdir mywebsite.git
cd mywebsite.git
git init --bare

Then create the file hooks/post-receive:

#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f

And make the file executable:

chmod +x hooks/post-receive

On your local computer,

git remote add production git@myserver.com:mywebsite.git
git push production +master:refs/heads/master

Yes, that's it!Now, in the future, you can deploy your changes using git push production!

The reputation of this solution is due to http://sebduggan.com/blog/deploy-your-website-changes-using-git/ .Find a more detailed explanation of what happened here.

Posted by hennety on Sat, 14 Dec 2019 18:53:33 -0800