Logo Questions Linux Laravel Mysql Ubuntu Git Menu

git push commit to different branch

Sorry, this maybe a stupid question, but I just couldn't figure it out the problem.

I have cloned a branch via git (bitbucket), changed some files, commited these and pushed them back to the remote origin.

Now I want to push this commit to a different branch which is partly ahead and behind of the current branch. So I tried: git push origin HEAD:differentBranch, but this didn't work ("Updates were rejected because a pushed branch tip is behind its remote counterpart").

How can I fix this? Sorry again, my skills in git are still developable.

like image 351
Maximilian Stölzle Avatar asked Mar 15 '23 20:03

Maximilian Stölzle

1 Answers

You can do that by using git cherry pick. So you can try like this:

git checkout differentBranch
git cherry-pick <commit # from previous commit from your first branch>
like image 182
Deepak Biswal Avatar answered Mar 17 '23 12:03

Deepak Biswal