git push origin master not pushing the files

后端 未结 2 1079
眼角桃花
眼角桃花 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:01

    You are probably pushing to a bare repository. You must clone it someplace and pull from the remote in order to see live changes.

    To create a bare repository at myPath; you'll need to be logged into a shell on myIP:

    1. mv myPath myPath2 # saves the live repository
    2. git clone --bare myPath2 myPath # creates the bare repository

    Now your push should work and follow @VonC's instructions above in configuring your post-receive hook.

    0 讨论(0)
  • 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 <PATH>/.git/hooks/post-receive

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

    0 讨论(0)
提交回复
热议问题