Reputation: 17511
I have seen that you can add a remote and state that it's pushurl is another remote.
For example, if I set my origin as
git remote add origin [email protected]:newrepo/newrepo.git
I can add a new remote and set its pushurl
to my origin:
git remote add oldremote [email protected]:oldrepo/oldrepo.git
git remote set-url --push oldremote [email protected]:newrepo/newrepo.git
So if I create a branch branch1
from oldremote/branch1
git fetch oldremote branch1
git checkout -b branch1 oldremote/branch1
It will pull from oldremote/branch1
and push to origin/branch1
This works as expected. Doing git pull
pulls from oldremote
(and says we're up to date) and pushes to origin
. Nice and easy.
Now I'm trying to create a branch that doesn't have the same name as its remote branch. Secifically, I want to track oldremote/master
as local branch legacy
, and have this local branch to push to origin/legacy
.
git fetch oldremote master
git checkout -b legacy oldremote/master
Now, this has two side effects.
First, doing git push
doesn't push to origin/legacy
. I have to do git push origin legacy
.
Second, doing git pull
doesn't just fetch and merge from oldremote/master
. It fetches every branch from oldremote
.
TL/DR
Is there a way to pull from a branch in one remote and push to another branch in another remote when branch names are different?
Upvotes: 1
Views: 181
Reputation: 30956
git config branch.legacy.remote oldremote
git config branch.legacy.pushremote origin
git config branch.legacy.merge refs/heads/master
git config --local -e
should look like:
[remote "oldremote"]
url = [email protected]:oldrepo/oldrepo.git
fetch = +refs/heads/*:refs/remotes/oldremote/*
[remote "origin"]
url = [email protected]:newrepo/newrepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = oldremote
merge = refs/heads/master
[branch "legacy"]
remote = oldremote
pushremote = origin
merge = refs/heads/master
Note that the value of push.default
should be unset or simple
. As the manual says, simple
has become the default in Git 2.0. If its value is not simple
or unset, git push
may fail.
Upvotes: 3