简体   繁体   中英

Use case for pushing remote branches to another remote repo in git

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?

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 .

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