简体   繁体   English

git push到远程主分支

[英]git push to remote master branch

I have a remote and a local git repository. 我有一个远程和本地git存储库。
Local repository is clone from the remote. 本地存储库是从远程克隆的。
When I modify my local repository and commit to the master branch. 当我修改本地存储库并提交到master分支时。
Then I run " git push " to remote repository. 然后我运行“ git push ”到远程存储库。
But it failed and output the following msg. 但它失败并输出以下消息。

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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

I "git checkout -b current" another branch in the remote repository. 我将远程存储库中的另一个分支“ git checkout -b current”。
In my local repository, I run "git push" then it success. 在我的本地存储库中,我运行“ git push”,然后成功。
But the local modification only push to the remote master branch. 但是本地修改只能推送到远程主分支。
Then I should run "git merge master" in the remote repository to take the change. 然后,我应该在远程存储库中运行“ git merge master”以进行更改。

I'm newbie to git. 我是git的新手。
Am I doing wrong? 我做错了吗?

The remote repository is not a bare repository and has master checked out. 远程存储库不是裸存储库,并且已检出主数据库。 And, by default, git doesn't allow you to push to the checked out branch of a non-bare repo. 而且,默认情况下,git不允许您推送到非裸仓库的已签出分支。

Remote repos to which you push should be set up as bare repo ( git init --bare ) ideally. 理想情况下,应将您要推送到的远程存储库设置为裸存储库( git init --bare )。

manojlds' answer is correct, however it might help to know what the purpose of your remote repo is. manojlds的回答是正确的,但是这可能有助于了解远程回购的目的。

  • If the remote repo is just for backup / collaboration purposes -> you've got the right idea, just replace the remote repo with a 'bare' one and go from there. 如果远程回购仅用于备份/协作目的->您有正确的主意,只需将远程回购替换为“裸露”,然后从那里去。
  • If the remote repo is the production server, then you're doing things wrong -> you should have a different configuration. 如果远程仓库是生产服务器,那么您做错了->您应该具有不同的配置。

A good confiruation so that you can "push to production" is to have your 'bare' repo for backup / collab purposes, then you have a seperate repo which is setup on the deployment server and is cloned from the bare repo. 一个很好的确认是,您可以将“裸”存储库用于备份/协作目的,以便“推向生产”,然后您可以在部署服务器上设置一个单独的存储库,并从裸存储库中克隆该存储库。 Then on the bare repo and you can put a 'post-receive hook' which makes the deployment repo do a pull. 然后,在裸仓库上,您可以放置​​一个“后接收挂钩”,这使部署仓库进行拉动。

I'm sure there are guides on how to do this... I followed one myself once :) 我敢肯定有关于如何执行此操作的指南...我自己追踪了一次:)

When i was new to github my mentor gave me this thumb rule to follow: 当我不熟悉github时,我的导师给了我这个遵循的经验法则:

Make modifications to your code locally. 在本地修改您的代码。 When it is time to commit, do the following: 当需要提交时,请执行以下操作:

  1. do git pull (very important to sync the inner reference headers of remote repo to your local repository) 进行git pull (将远程回购的内部引用标头同步到本地存储库非常重要)
  2. If there are any conflicts in different files Merge them carefully by either choosing your copy or remote copy or a mix of both by opening both the files in Kdiff. 如果不同文件中存在任何冲突,请选择副本或远程副本,或者通过在Kdiff中打开两个文件,将二者混合使用,以谨慎地合并它们。 Once you have resolved all the conflicts push the merge. 解决所有冲突后,请推送合并。
  3. After step 2 do git push to save the local changes you made to the code which you wanted to commit in the first place. 在第2步之后,执行git push来保存对代码的本地更改,这些更改首先要提交。

Subversion can be a pain but it is extremely important to maintain the sync. 颠覆可能会很痛苦,但是保持同步非常重要。 These set of rules have helped me a lot to maintain sub version usingg github. 这些规则对我使用github维护子版本很有帮助。 Hope this helped. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM