Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push commits to another branch

Tags:

git

git-branch

Is it possible to commit and push changes from one branch to another.

Assume I commited changes in BRANCH1 and want to push them to BRANCH2.

From BRANCH1, is it valid to do:

git push origin **BRANCH2** 

And then reset BRANCH1?

like image 578
jviotti Avatar asked Dec 16 '12 01:12

jviotti


People also ask

Can I push commit to another branch?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.


1 Answers

That will almost work.

When pushing to a non-default branch, you need to specify the source ref and the target ref:

git push origin branch1:branch2 

Or

git push <remote> <branch with new changes>:<branch you are pushing to>  
like image 111
SLaks Avatar answered Oct 08 '22 03:10

SLaks