Git push error '[remote rejected] master -> master (branch is currently checked out)'

前端 未结 30 2015
半阙折子戏
半阙折子戏 2020-11-22 00:07

Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.

I am now

相关标签:
30条回答
  • 2020-11-22 00:42

    Check your .git/config in the destination project:

    $ cat .git/config 
    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
    [receive]
        denyCurrentBranch = updateInstead
    

    If the core. bare is false, you can set it to true:

    $ git config core.bare true
    

    and then in your local push to remote:

    git push remote_repo   // suppose the destination repo is remote_repo
    

    it will success, in the remote_repo you can check git version.

    $ git log -1
    commit 0623b1b900ef7331b9184722a5381bbdd2d935ba
    Author: aircraft < aircraft_xxx@126.com>
    Date:   Thu May 17 21:54:37 2018 +0800
    

    and now you can not use git in your "workspace":

    $ git status
    fatal: This operation must be run in a work tree
    

    you should set bare.bare back to false.

    $ git config core.bare false
    
    0 讨论(0)
  • 2020-11-22 00:43

    You can recreate your server repository and push from your local branch master to the server master.

    On your remote server:

    mkdir myrepo.git
    cd myrepo.git
    git init --bare
    

    OK, from your local branch:

    git push origin master:master
    
    0 讨论(0)
  • 2020-11-22 00:43

    In fact, set the remote to a non-checked out branch is sufficient. After you checked out your remote in a different branch, you can push.

    0 讨论(0)
  • 2020-11-22 00:44

    I had the same issue. For me, I use Git push to move code to my servers. I never change the code on the server side, so this is safe.

    In the repository, you are pushing to type:

    git config receive.denyCurrentBranch ignore
    

    This will allow you to change the repository while it's a working copy.

    After you run a Git push, go to the remote machine and type this:

    git checkout -f
    

    This will make the changes you pushed be reflected in the working copy of the remote machine.

    Please note, this isn't always safe if you make changes on in the working copy that you're pushing to.

    0 讨论(0)
  • 2020-11-22 00:45

    I had the same problem using Git to synchronise repositories on my Android phone and laptop. The solution for me was to do a pull instead of a push, as @CharlesBailey suggested.

    git push origin master on the Android repository fails for me with the same error messages that @hap497 got because of a push to a nonbare checkout of a repository + working-copy.

    git pull droid master on the laptop repository and working-copy works for me. Of course, you need to have previously run something like git remote add droid /media/KINGSTON4GB/notes_repo/.

    0 讨论(0)
  • 2020-11-22 00:45

    My solution (in use)

    1. Checkout "master" on remote server
    2. Work locally on "dev" branch
    3. Push changes to remote dev
    4. Merge dev into master on remote

    bingo

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