push from local branch to different remote branch
Asked Answered
S

2

22

I have 2 branches named developer and Current on remote. In local I'm working on branch developer and I push my changes to remote developer. The question is, how can I push from local developer to remote Current?

I have tried these:

git push origin Current -f
// error:
// src refspec Current does not match any.
// failed to push some refs to ...

// and this one too:
git config push.default upstream
git push origin Current -f
// error: same as the first try

// and this one too:
git branch --set-upstream-to developer origin/Current
// or:
git branch --set-upstream-to developer Current
// error: fatal: branch 'Current' (or 'origin/Current') does not exist
Stetson answered 3/2, 2015 at 13:51 Comment(1)
git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>] - your syntax is screwed up.Sesterce
T
36

You can do:

git push origin developer:current

This will push branch developer from your local repo to branch current on the remote repo. In case you are overwriting changes on branch current, you will need to use the -f flag as well.

FWIW, doing a git push origin :current (note the : before current) will delete the branch current from the remote.

Toscanini answered 3/2, 2015 at 15:38 Comment(1)
FYI this pushes developer to current without making current the upstream branch of developer. Ie. if developer is set to track origin/developer, running this command will not change that. Personally, this is what I was looking forFishnet
W
1

While on your developer branch, try git push -u origin Current. -u is shorthand --set-upstream. It looks like using --set-upstream with git branch requires the upstream branch to already exist; this isn't the case when using it with git push.

Waksman answered 3/2, 2015 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.