git push origin master not pushing the files

后端 未结 2 1083
眼角桃花
眼角桃花 2021-01-06 22:39

I have setup my remote git and local git on my mac I was able to create a git repo (git init myrepo) on the remote machine (Linux) Added few files and committed them no prob

2条回答
  •  悲&欢浪女
    2021-01-06 23:04

    You are pushing to a non-bare repo (which works because of the receive.denyCurrentBranch being set to ignore).

    But it it possible that your remote non-bare repo:

    • has checked out a different branch than master (and since you are pushing to master, the content of the working tree wouldn't change)
    • or has checked out a commit (meaning you are in a detached HEAD state, which you can confirm with a git branch inside that repo, to see if any of those branches is marked as checked out or not).

    I have deleted both repos on local and remote and created it again (No bare for sure)

    By default, receive.denyCurrentBranch is set to 'refuse', so your error messages are consistent with that.

    Try setting it on 'ignore', and since your remote repo is on master, your push will go through.

    But you won't see any file: you need a post-receive hook which would checkout your working tree or reset it to HEAD, for the files to actually appear.

    See for instance "Git: making pushes to non-bare repositories safe"

    my post-receive hook looks like this:

    export GIT_WORK_TREE=..
    git checkout -f HEAD
    

    The OP reports in the comments:

    the answer to the original issue is run this on the remote server:

    git config receive.denyCurrentBranch ignore 
    

    Then Add export GIT_WORK_TREE=.. git checkout -f HEAD To your gitrepo /.git/hooks/post-receive

    That did the trick and I am now able to push files from my local to the remote repo!!!

提交回复
热议问题