I have a local repo set up on my laptop's hard drive, at c:\\someFolder\\.git
. I want to set up a remote repo on a Windows server at x:\\someOtherFolder
as a backup. Here are the steps I have taken so far:
In x:\\someOtherFolder
, opened a git bash session and entered git clone "c:\\someFolder"
. Got the message Cloning into 'someFolder'...done.
In c:\\someFolder
, opened a git bash session and entered git remote add origin "x:\\someOtherFolder"
. Statement executed without response.
Made some changes in the local project files and committed them to the local repo with git commit -am
.
From the c:\\someFolder
git bash, entered git push origin master
. Response is:
--
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.
etc.
I feel like I probably set up the remote incorrectly. What should I do instead?
Remote server can be only a bare repository (repository without content).
In order to have such a repository you need to create it with the --bare
flag
# create a (bare) remote repository
git init --bare
Now you should see the content of the .git
folder as the file system of that repository and you can start using it.
Remote repository does not have any working directory. It simply contains all the content pushed into it from all other local repositories.
To the user who did a down vote and commented out that you don't need a bare repository: you don't need it but this is the convention.
Read all about it in here: https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server
In order to initially set up any Git server, you have to export an existing repository into a new bare repository – a repository that doesn't contain a working directory .
This is generally straightforward to do.
In order to clone your repository to create a new bare repository, you run the clone command with the --bare option.
No, you did everything right, you've just got into a special situation.
That is, during the push git updates the specified references in the remote repo. In your example this is master
branch in someOtherFolder
. It's Ok, but since master
branch is being checked out currently, then git prevents the push by default, preserving possible changes in the remote directories.
You have three options:
Nevertheless, you still can push into someOtherFolder
if you think it's intended. Perform git push --force
and don't forget to reset the working tree of someOtherFolder
with git reset --hard
issued from within someOtherFolder
. This, however, is useful only for a few special cases. Suppose, someOtherFolder
is a "puppet repository" which should contain only changes made in someFolder
repository. You might find useful to set receive.denyCurrentBranch = warn
configuration setting in someOtherFolder
.
push your changes into another branch in someOtherDirectory
: git push origin master:another_master
. Thus you will create branch another_master
in someOtherFolder
only and can do whatever you want with master
in it then.
A more typical solution would be to fetch new changes made in someFolder
into someOtherFolder
: inside someOtherFolder
perform git fetch
and you will get new changes in the remote branch origin/master
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.