简体   繁体   English

Git-推送到远程存储库

[英]Git - pushing to remote repository

Git newbie here. Git新手在这里。

created a new folder: 创建了一个新文件夹:

mkdir hello_master
cd hello_master
touch test.txt
git init
git add test.txt
git commit test.txt

then cloned the repository 然后克隆存储库

    git clone hello_master hello_local
    # made some changes to test.txt and committed it

how do I push it to hello_master ? 如何将其推送到hello_master if I do a git push, it is complaining saying I can't push to hello_master . 如果我执行git push,则抱怨说我无法推送到hello_master But if I go to hello_master , I can pull and get all changes from hello_local . 但是,如果我转到hello_master ,则可以从hello_local提取所有更改。

What am I doing wrong? 我究竟做错了什么?

Nothing. 没有。 You just can't push to a non-bare repository. 您只是无法推送到非裸仓库。 Because git wouldn't know what to do with the checked-out files. 因为git不知道如何处理检出的文件。

It is only recommended that you do not push to a non-bare repo. 仅建议您不要推送到非裸仓库。 There are ways to push to a non-bare repo ( of course! ): 有几种方法可以推送到非裸仓库(当然!):

1) The error message in itself would talk about setting the receive.denyCurrentBranch config to warn or ignore. 1)错误消息本身将涉及将receive.denyCurrentBranch配置设置为警告或忽略。

2) Checkout a new branch ( say temp) in the repo. 2)在存储库中签出一个新分支(例如temp)。 Now you can push master or any other branch. 现在,您可以推送master或任何其他分支。

You provided not much information, but i suppose, you have 'push to non-bare repo' problem. 您提供的信息不多,但是我想,您遇到了“推向非裸仓库”的问题。
Using Git, you cannot push to non-bare repository (repository, which have working copy) to active branch, because somebody may be working in this branch and you can ruin his work. 使用Git,您不能将非裸存储库(具有工作副本的存储库)推送到活动分支,因为有人可能正在该分支中工作,并且您可能会破坏他的工作。
Solution 1 is to make main repository bare; 解决方案1是使主存储库裸露;
solution 2 is to checkout hello_master to another branch; 解决方案2是将hello_master签出到另一个分支;
solution 3 (from git help) : 'You can set 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into its current branch; 解决方案3(来自git help):'您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为'ignore'或'warn',以允许压入其当前分支; however, this is not recommended unless you arranged to update its work tree to match what you pushed in some other way. 但是,除非您安排更新其工作树以匹配您以其他方式推送的内容,否则不建议这样做。

I suspect the answer you're looking for is here: https://git.wiki.kernel.org/index.php/GitFaq#How_would_I_use_.22git_push.22_to_sync_out_of_a_host_that_I_cannot_pull_from.3F 我怀疑您正在寻找的答案在这里: https : //git.wiki.kernel.org/index.php/GitFaq#How_would_I_use_.22git_push.22_to_sync_out_of_a_host_that_I_cannot_pull_from.3F

but in brief, you can't push directly, you have to create a branch-ish-thing on the remote side. 但总而言之,您不能直接进行推送,而必须在远程端创建分支式的东西。 It looks like this: git push remote-box:/path/to/git/repo master:refs/remotes/name-of-local-box/master 它看起来像这样:git push remote-box:/ path / to / git / repo master:refs / remotes / local-box-name / master

Then when you log in to "remote-box", you can merge in changes you pushed from the other machine like this: git merge name-of-local-box/master 然后,当您登录“ remote-box”时,可以像这样从另一台计算机中合并您推送的更改:git merge name-of-local-box / master

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

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