开发者

Git - pushing to remote repository

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?


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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜