Why can't I push to this bare repository?

后端 未结 6 1934
生来不讨喜
生来不讨喜 2020-12-07 07:10

Can you explain what is wrong with this workflow?

$ git init --bare bare
Initialized empty Git repository in /work/fun/git_experiments/bare/
$ git clone bare         


        
6条回答
  •  太阳男子
    2020-12-07 07:56

    Try this in your alice repository (before pushing):

    git config push.default tracking
    

    Or, configure it as the default for your user with git config --global ….


    git push does default to the origin repository (which is normally the repository from which you cloned the current repository), but it does not default to pushing the current branch—it defaults to pushing only branches that exist in both the source repository and the destination repository.

    The push.default configuration variable (see git-config(1)) controls what git push will push when it is not given any “refspec” arguments (i.e. something after a repository name). The default value gives the behavior described above.

    Here are possible values for push.default:

    • nothing
      This forces you to supply a “refspec”.

    • matching (the default)
      This pushes all branches that exist in both the source repository and the destination repository.
      This is completely independent of the branch that is currently checked out.

    • upstream or tracking
      (Both values mean the same thing. The later was deprecated to avoid confusion with “remote-tracking” branches. The former was introduced in 1.7.4.2, so you will have to use the latter if you are using Git 1.7.3.1.)
      These push the current branch to the branch specified by its “upstream” configuration.

    • current
      This pushes the current branch to the branch of the same name at the destination repository.

      These last two end up being the same for common cases (e.g. working on local master which uses origin/master as its upstream), but they are different when the local branch has a different name from its “upstream” branch:

      git checkout master
      # hack, commit, hack, commit
      
      # bug report comes in, we want a fix on master without the above commits
      
      git checkout -b quickfix origin/master  # "upstream" is master on origin
      # fix, commit
      git push
      

      With push.default equal to upstream (or tracking), the push would go to origin’s master branch. When it is equal to current, the push would go to origin’s quickfix branch.

    The matching setting will update bare’s master in your scenario once it has been established. To establish it, you could use git push origin master once.

    However, the upstream setting (or maybe current) seems like it might be a better match for what you expect to happen, so you might want to try it:

    # try it once (in Git 1.7.2 and later)
    git -c push.default=upstream push
    
    # configure it for only this repository
    git config push.default upstream
    
    # configure it for all repositories that do not override it themselves
    git config --global push.default upstream
    

    (Again, if you are still using a Git before 1.7.4.2, you will need to use tracking instead of upstream).

提交回复
热议问题