0

In git, we can push a remote branch to another remote like this:

> git clone git@foo1.com:a/a
> cd a
> git remote add other git@foo2.com:b/b
> git fetch --all
# ...
> git push origin other/master
Counting objects: 107, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (66/66), done.
Writing objects: 100% (107/107), 2.11 MiB | 0 bytes/s, done.
Total 107 (delta 52), reused 87 (delta 33)
remote: Resolving deltas: 100% (52/52), completed with 8 local objects.
To foo1.com:a/a
 * [new branch]        other/master -> other/master

So on "@foo1.com:a/a", we can see it got the remote of "foo2.com:b/b", by using the git branch -va command:

* master                  7c6051f foo
  remotes/other/master    38a5a1b bar

If we just use git branch -v this remote branch wouldn't appear.

However I can't think how this is useful. There is no way for my local to interact with this on foo1.com:a/a right? Could someone gives a potential use case for this?

Also could this somehow be disabled with some git configuration?

lulalala
  • 17,572
  • 15
  • 110
  • 169

1 Answers1

0

So on "@foo1.com:a/a", we can see it got the remote of "foo2.com:b/b", by using the git branch -va command:

No you don't: git branch -av is purely a local command, which lists local branches done in your local repo.
That branch remotes/other/master is not present on your remote repo foo1.com:a/a. Only master is.

remotes/other/master is a local "remote tracking branch" meant for your local repo to remember what was pushed to or pull from the remote repo "other" for the branch "master".

git push origin other/master

That would indeed create another branch named other/master to the remote repo origin (foo1.com)

But you usually don't need that: you do a local merge between the local remote tracking branch other/master and your own master, then push master itself with a simple git push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I ran `git branch -va` on the "@foo1.com:a/a" remote server's repository, and it's indeed there, with the correct SHA for b/b's master – lulalala Oct 12 '18 at 05:40
  • Thanks, so I guess you also think this has no use case and could be banned with no sideeffects? – lulalala Oct 12 '18 at 06:27
  • @lulalala yes, that would not be a usual use case, but it cannot be banned easily: https://stackoverflow.com/a/30471886/6309 – VonC Oct 12 '18 at 06:50