0

On my local PC, a have a repo (A) of a web project. On the same PC I have several deployments (B, C) of that project and sometimes it's more convenient to develop and test new features in those deployments.

I wonder how can I connect those deployments via git to use the same codebase (but create different branches). One way would be to use a common remote repo, push changes (from, say, A) there and pull those back to another local repo (B), but ideally I'd like to update those without access to the remote repo (by doing a git command like git push or git pull). Is this possible with git? Or do I have to install something like git service?

What I've tried to implement the suggestion by torek by the following steps:

  1. created 2 folders, "repo1" and "repo2" in a folder, let's call it "D:\path\to\repos"
  2. initialized git in both (git init)
  3. in repo1, created a file, added and commited it;
    did git remote add second file:///D:/path/to/repos and git push second master

but got the following:

Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
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: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To file:///D:/path/to/repos/repo2/
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'file:///D:/path/to/repos/repo2/'
YakovL
  • 7,557
  • 12
  • 62
  • 102
  • 1
    Have you tried to pull from A directly to B or vice versa? – phd Feb 17 '19 at 19:52
  • 2
    A remote is another Git repository, and the syntax for a URL for a remote includes `file://path/to/repo` or the simplified variant, `path/to/repo`. In this case your own Git runs on *both sides* of the conversation, talking to itself. – torek Feb 17 '19 at 20:00
  • @torek thanks for the pointer, I should have tried that myself in the first place, but this didn't work (see the edit). I guess, I have to set the path correctly. Or did I miss something about your suggestion? – YakovL Feb 17 '19 at 20:37
  • 1
    The short answer here is "pull into `second` from `first` rather than pushing from `first` to `second`". That ensures the checked out copy in `second` matches the state of the branch. – Amber Feb 17 '19 at 20:38
  • @Amber great, that worked! – YakovL Feb 17 '19 at 20:49

0 Answers0