Git - pushing to remote repository

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

Git newbie here.

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? if I do a git push, it is complaining saying I can't push to hello_master. But if I go to hello_master, I can pull and get all changes from hello_local.

What am I doing wrong?

回答1:

Nothing. You just can't push to a non-bare repository. Because git wouldn't know what to do with the checked-out files.



回答2:

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.

2) Checkout a new branch ( say temp) in the repo. Now you can push master or any other branch.



回答3:

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.
Solution 1 is to make main repository bare;
solution 2 is to checkout hello_master to another branch;
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; however, this is not recommended unless you arranged to update its work tree to match what you pushed in some other way.



回答4:

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

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!