1

I am new to git and I am running into the following issue- I created a branch 'Test' from develop. I am trying to pull changes from branch 'Working' (which is also based on develop) onto my local branch. I don't want any of my changes to affect develop or 'Working'. How would I do this?

I am not sure whether this is a merge or a rebase.

  • It would be a merge `Working > Test`. First checkout the *destination* branch, the one *receiving* changes, so your branch Test. Then merge the *source* branch, with `git merge Working` (be sure you do have a local version of this branch. If not, either pull it or merge the remote ref, which could be `origin/Working` depending on your remote setting) – Romain Valeri Dec 02 '22 at 16:02

1 Answers1

1

Either will work, but the result is different.

  • git merge working will create a single, new merge commit which combines the history of both branches. The commits are shared by both branches.
  • git rebase test working^{commit} && git push . HEAD:test && git checkout test will rebase, i.e. copy, the commits on working to test. The commits are now duplicated and separate versions of the commits exist in both branches.

The third option is to cherry-pick, which is similar to rebase, but switches source and destination.

  • git cherry-pick test..working will cherry-pick, i.e. copy, the commits on working and apply them to your test branch. The commits are duplicated and separate in both branches.

History after merge:

      D-E         -- working
     /   \
A-B-C     \       -- development
   \       \
    F-G-----M     -- test (M = merge commit)

History after rebase or cherry-pick:

      D-E         -- working
     /
A-B-C             -- development
   \    
    F-G-C'-D'-E'  -- test (C', D', E' = copied commits)
knittl
  • 246,190
  • 53
  • 318
  • 364