Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot push into git repository

Tags:

git

This is what I have done so far and I will say this procedure worked on Ubuntu 9.10 which perhaps had a different version of git.

server: mkdir ~/git  local: scp -r /../project [email protected]:~/git/ server: cd git         cd project         git init          git add .         git commit -a -m "initial"  local: git clone [email protected]:/../git/project /home/name/project    cd project    capify .  (from the ruby gem capistrano)    git add .    git commit -a -m "capified"    git push 

When I try to push this out I get this error message:

   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: error: is denied, because it will make the index and work tree inconsistent    remote: error: with what you pushed, and will require 'git reset --hard' to match    remote: error: the work tree to HEAD.    remote: error:     remote: error: You can set 'receive.denyCurrentBranch' configuration variable to    remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into    remote: error: its current branch; however, this is not recommended unless you    remote: error: arranged to update its work tree to match what you pushed in some    remote: error: other way.    remote: error:     remote: error: To squelch this message and still keep the default behaviour, set    remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.    To ...    ! [remote rejected] master -> master (branch is currently checked out)    error: failed to push some refs to 
like image 516
cards Avatar asked Jul 11 '10 04:07

cards


People also ask

Why is push not working in git?

If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.

Why can't I push code to GitHub?

To push a branch on remote, your branch needs to have the latest changes present in remote repository. If you get the failed to push error, first do git pull the branch to get the latest commits and then push it.


2 Answers

At server side, do this:

git config receive.denyCurrentBranch ignore 

Then you can push at local.

like image 84
HaveF Avatar answered Sep 23 '22 04:09

HaveF


Pushing to a non-bare repo is now possible (Git 2.3.0 February 2015).
And it is possible when you are pushing the branch currently checked out at the remote repo!

See commit 1404bcb by Johannes Schindelin (dscho):

receive-pack: add another option for receive.denyCurrentBranch

When synchronizing between working directories, it can be handy to update the current branch via 'push' rather than 'pull', e.g. when pushing a fix from inside a VM, or when pushing a fix made on a user's machine (where the developer is not at liberty to install an ssh daemon let alone know the user's password).

The common workaround – pushing into a temporary branch and then merging on the other machine – is no longer necessary with this patch.

The new option is:

updateInstead 

Update the working tree accordingly, but refuse to do so if there are any uncommitted changes.

That is:

git config receive.denyCurrentBranch updateInstead 
like image 30
VonC Avatar answered Sep 19 '22 04:09

VonC