15

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

1 Answer 1

30

Follow these steps:

  1. Go to the folder you want to have your remote in

    $ cd /path/to/my-remote 
  2. Create a bare repository there via git init

    $ git init --bare 
  3. 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 
  4. 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.

Sign up to request clarification or add additional context in comments.

6 Comments

@AnimiVulpins Thank you!
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 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?)
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
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)"
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.