1

The remote has two branches: mainline and release-x.

I pushed one recent feature from my local branch to remote mainline, But I don't how to also push this feature into the release-x branch.

Any suggestion would be appreciated. Thank you.

Bostonian
  • 615
  • 7
  • 16
  • This should work for you: [git cherry-pick](https://stackoverflow.com/questions/36778375/git-apply-a-commit-on-another-branch-to-the-working-copy) the commit in your local repository, then push the change on remote – Alexey S. Larionov Mar 26 '20 at 20:51

2 Answers2

1

You have multiple possibilities:

At first, make sure that you have the branches locally. This can be done by calling git pull origin mainline and git pull origin release-x.

copy the commit

Go to release-x branch(check out a local copy) and copy the commit to that branch using git cherry-pick <commit hash>

Don't forget to execute git push origin release-x after that.

merge it

You can also merge all changes from mainline to release-x by checking out release-x and runing git merge release-x or git merge <commit hash> if you want to merge the difference until a commit in mainline.

Don't forget to execute git push origin release-x after that.

just push it

If you want to copy all changes from mainline to release-x, and release-x is 0 commits behind mainline, you can also push mainline to release-x using git push origin mainline:release-x

overwrite it (STRONGLY DISCOURAGED)

You can also completely overwrite the remote content of release-x with the content of mainline using git push -f origin mainline:release-x. But this will remove all changes made to release that are not committed in mainline. If you want to do that despite this, I suggest you to use --force-with-lease as it does not overwrite the remote if another person pushed to it without you knowing.

dan1st
  • 12,568
  • 8
  • 34
  • 67
  • For the first suggestion, what do you mean `Go to release-x branch`? You mean set up a local branch tracking remote `release-x`? Thanks. – Bostonian Mar 26 '20 at 21:40
0

Specify the full remote and branch to push to. The remote you cloned from is origin.

git push origin release-x

See "Pushing to Your Remotes" in Working With Remotes in the Git Book.

This will only work if your local branch and release-x have a common ancestor. It may not be the best way to manage your release branch, it depends on your release process.

Schwern
  • 153,029
  • 25
  • 195
  • 336