Question

So I have two branches on git: develop and release. I have been using the develop branch until now. I just made a commit to the develop branch which I want to be available in the release branch. How do I do it? I am a little confused here.

1) Does this automatically happen when I do git checkout -b release

2) To switch back to the develop branch, I can just do a checkout, right? or do I need to do a merge?

Was it helpful?

Solution

You have a few options for making a commit on one branch available to another -- which you choose depends on how you want your history to look, later.

  1. A merge will create a commit on the release branch that has two parents: the tip of develop and the former tip of release. release will then have all of the work from develop and release. To merge develop into release, make sure you have a clean working copy, and run git checkout release, then git merge develop.
  2. You can also cherry-pick individual commits that were made from develop on top of release. Cherry-picking creates a new commit on release that performs the exact changes that were done in a commit you name. This is useful if you've done a bunch of work on develop, but you only want one or two things brought over. To cherry-pick, look at git log, copy the sha hash that names the commit you want, and run git checkout release, then git cherry-pick <commit hash>.
  3. If you need to move some big range of commits from one to the other, you can use rebase --onto. It's a bit more advanced, but you can read about it if you're curious.

To answer your follow-on questions:

  1. Nope! The general purpose of git checkout is to make your working copy look like a thing that you name. When you run git checkout release, git will change the actual files in your working copy to the state that was last committed to release. Checkout doesn't change existing branches. (Also, you don't need the -b if release already exists; checkout -b is a convenient shortcut to create and checkout a branch in one shot.)

  2. Along the same lines, to switch back, all you'd need to do is git checkout develop again.

OTHER TIPS

If you want to bring changes from one branch to another, you have to do a merge.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top