4

My scenario is I've two branches master and feature_swap I want to work parallelly with these two, they have different basic functionality. sometimes I may update some utility classes in master that I want to test with the other branch. Then I might even carry the same changes in another branch If I get expected output.

I've already created two branches. and updated master with few changes in util. and I want to test the same with feature_swap. (without merging)

Whats the best way to do it ? or how should I do it ?

If I just do git pull feature_swap it auto merges in the wrong way. What I want is the basic functionality of feature_swap (swaping some data before reporting) would stay as it is. all other implementations may be changed when master changes

Update

I am a noob :( and first time doing branching. My project is on bitbucket. There is a Tool to compare branches. If I put master on left and feature_swap at right. It shows

$ git checkout feature_swap
$ git merge remotes/user_name/project_name/master

But I think If I do that it will merge master -> feature_swap (am I wrong). But I want those changes but keep developing feature_swap in parallel.

and also is it a problem is developing feature_swap in a parallel flow even if I merge from master ?

Dipro Sen
  • 4,350
  • 13
  • 37
  • 50

2 Answers2

1
rebase --interactive

This sounds like a situation where an interactive rebase may be helpful. It provides you more control as to what get included and what is left out in a rebase, and even can help you change or squash old commits. There are a lot of posts to reference this topic, such as this one. It is an alternative to cherry-picking all the util commits you want.

Community
  • 1
  • 1
Magikhead
  • 124
  • 1
  • 6
0

git pull --rebase master
will keep your custom changes on top of masters changes and give you the chance to correct them before merging.

git pull --no-commit --no-ff master
will pull the changes and let you fix any conflicts before merging.

git cherry-pick COMMIT-ID
will let you bring one commit over from one branch to another.

Hopefully one of these approaches will help.

Neel Basu
  • 12,638
  • 12
  • 82
  • 146
Jamund Ferguson
  • 16,721
  • 3
  • 42
  • 50
  • right now I am in the master branch. and I want to **safely** pull `feature_swap` So I'd do `git pull feature_swap --no-commit -no-ff` ? – Dipro Sen Sep 29 '12 at 16:03
  • I did a `git pull --no-commit --no-ff origin feature_swap` It asked for password. It shown ` * branch feature_swap -> FETCH_HEAD` when I do `git log` Its showing the last commit of `master` and `git branch` is still showing `* master` ` – Dipro Sen Sep 29 '12 at 16:08
  • I did `git pull --rebase origin feature_swap` which is still showing `*master` if I do `git branch` – Dipro Sen Sep 29 '12 at 16:32
  • @DiproSen I'm unclear as to what you're doing. You're in master, but you want to pull some features from the `feature_swap` branch? If so your best bet is to cherry-pick the commit IDs (found by typing `git log feature_swap`). If you want all of the changes from `feature_swap` to come into master, but maybe with some changes, then look at the variations of `git pull` – Jamund Ferguson Sep 29 '12 at 16:33
  • Your original post makes it sound like you want to add functionality to feature_swap, in which case you should start by checking out that branch. – Jamund Ferguson Sep 29 '12 at 16:38