I have a bare repository on my home-server to which I push from my
laptop for backup. Due to a new router I cannot push anymore from
within my home-LAN to the home-server using the global URL (something
to do with “NAT loopback”) but need to use the local LAN address. So my
.git/config now contains two remotes for the same bare repository:
[remote "home1"]
url = ssh://username@my.url/home/username/git_bare_repos/repo.git
mirror = true
[remote "home2"]
url = ssh://username@192.168.1.74/home/username/git_bare_repos/repo.git
mirror = true
So, questions: Is this ok? Are there potential hazards/pitfalls? And is there a better way to do this, so I wouldn’t have to use different commands depending on whether I’m at home or not?
It’s ok. They’re the same repo after all.
The only difference for you is that depending on your current location you’ll have to push/pull/etc from one remote or the other.
Git keeps a reference for every branch, tag, remote-tracking branch, etc. In fact, they are all references to commits, and they have a file representation in
.git/refs/....By comparing these references git knows the status of each branch, tag, etc. For example, if you compare
refs/heads/mastertorefs/remotes/origin/master, and the branches are not sync’d, then these refs will differ. To find which one is outdated, git can just verify if the remote commit exists in the local branch, and if it does, then the remote branch is outdated. This also allows git to tell you how many commits your local branch is ahead of the remote branch, and vice-versa.A more in-depth explanation can be found here.