简体   繁体   中英

How to have 2 git repositories in the same machine and pushing and pulling between them?

I would like to setup 2 repositories to push and pull between them, not by using a bare repository, if possible.

I have a server on which there are some designers working on that. As I will not introduce to them the git tool, because it's quite complex, I let them work in the server location. Then I want to keep on my pc a repository too, just in case somebody will delete the folder or I have to make changes while not at work.. (the server is like a shared disk in our network..)

If you're just using your PC as a backup then the simplest solution is to:

  1. use cron or similar on the server to auto-commit changes
  2. in that same job, push to a bare repo on your PC

This assumes you will mount the file system holding the bare repo on to your server to allow your server to write (git push) to it. If you don't do this you'll need to set up a git server. This is simple on Unix (gitd) but rather more involved on Windows (cygwin + gitd + sshd).

Alternatively...

  1. use cron or similar on the server to auto-commit changes (as above)
  2. use cron or similar on your PC to "git pull" changes from server to your PC (up to you to schedule server "git commit" so it completes before PC "git pull" kicks off)

This assumes you will mount the server filesystem on your PC (you only need read access).

I would advise not to git push in to a non-bare remote repo... otherwise your index would get out of step with your working copy and would likely lead to confusion.

You better use a github or bitbucket to host your repository. Otherwise you will have to run git server on one of machines.
BTW, git is not that complex, and you will get less trouble teaching your designers to use it than cleaning up the mess they can bring on your server.

Edit

If you have filesystem access to your server, you can git clone your repo using path to it:

git clone /path/to/repo local-repo
cd local-repo
git fetch /path/to/repo

Edit 2

For this to work you need to set the receive.denyCurrentBranch setting to ignore in the receiving repo:

git config receive.denyCurrentBranch "ignore"

in general the git devs don't want you to push to a non-bare repo. the idea is that a push only sends the changes to the .git folder not the changes to the working directory. if you were to push to a non-bare repo the work tree would actually be behind the HEAD.

now it is possible, but it envolves a lot more steps, here's some info on pushing to non-bare repos: http://sitaramc.github.com/concepts/bare.html

but i think the best solution, IMHO, is to keep a bare repo and push/pull/fetch to and from it with your two other repos.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM