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?
Asked
Active
Viewed 5,304 times
1 Answers
26
Follow these steps:
Go to the folder you want to have your remote in
$ cd /path/to/my-remote
Create a bare repository there via git init
$ git init --bare
Go 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-remote
After these steps you should be able to push to your new remote
<name-of-remote>
$ git push -u <name-of-remote> master
Where
-u
is used to set the upstream of your branch, only needed the first time you push.

Carlo Wood
- 5,648
- 2
- 35
- 47

AnimiVulpis
- 2,670
- 1
- 19
- 27
-
-
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. – JimSan Sep 12 '19 at 11:43
-
@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?) – AnimiVulpis Sep 18 '19 at 07:28
-
1Without 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 Jan 10 '20 at 14:10
-
1remote: 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)" – Carlo Wood Jan 10 '20 at 14:10
-
@CarloWood Thanks for your update on my answer. For empty local remotes a `--bare` repository is many times easier as it does not force you to set any unusual configs. – AnimiVulpis Jan 10 '20 at 17:08