I want to make a local push destination on my hard disk on Git, and use that destination(folder) for push and pull instead of adding an remote repository. How do I do that in Git?
1 Answer
Follow these steps:
Go to the folder you want to have your remote in
$ cd /path/to/my-remoteCreate a bare repository there via git init
$ git init --bareGo to the repository you want to work in and add a new remote pointing to the previously created repository via git remote add
$ git remote add <name-of-remote> /path/to/my-remoteAfter these steps you should be able to push to your new remote
<name-of-remote>$ git push -u <name-of-remote> masterWhere
-uis used to set the upstream of your branch, only needed the first time you push.
6 Comments
MihaiG
@AnimiVulpins Thank you!
JimSan
For an initial local remote and initial starting repo of source code, the --bare was the only thing that worked for me. Just doing git init ./ gave me errors when I did git push.
AnimiVulpis
@JimSan It would be really helpful to know what errors you got and what you mean by: "Initial starting repo of source code" (a repository with no commits yet?)
Carlo Wood
Without the --bare I get half a page of error when trying to push to it: "remote: error: refusing to update checked out branch: refs/heads/master error: By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent with what you pushed, and will require 'git reset --hard' to match the work tree to HEAD. You can set the 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into
Carlo Wood
remote: 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. To squelch this message and still keep the default behaviour, set 'receive.denyCurrentBranch' configuration variable to 'refuse'. To /home/carlo/projects/aicxx/ai-evio-testsuite/tmp/my_remote2 ! [remote rejected] master -> master (branch is currently checked out)"
|