tags:

views:

53

answers:

2

I am relatively new to Git, and I'm still not very comfortable with it. Right now, I'm looking for the command/options/magic that can make the current branch look like another branch; that is, to merge them, but when a conflict arises, to always choose the difference in the branch that is being merged into the current one.

My situation is thus; I have an stable(ish) application on the "master" branch. I also have another branch, called "feature". I basically want to make changes/additions/deletions to feature until I like the new feature I'm working on. Once I feel it is ready, I want to make the master branch look identical to the feature branch.

I know this probably isn't a best practice, but as I said, I'm new to Git. I plan on learning how to do more complicated things in the future, but for now, this is all I need.

Thanks, SO!

+3  A: 

Sorry! Didn't read all the way through before answering...

git checkout master
git merge feature

This will work effortlessly if you have not made any changes to master since you branched feature off it.

And what you are trying to do is exactly the way that branching and merging are supposed to work. Develop your features on a branch, when you have it stable and working like you want it to work, merge it back into the master branch.

kubi
what if I made a change to master that might cause a conflict? I guess I should have mentioned that possiblity, because it is possible I might need to make a change to something small.
G. Martin
@G. Martin AFAIK There should not be a problem. Perform `git checkout master` on the feature branch will bring up any merging problems. Once you have resolved those `git merge feature` on the master branch should not have any problems.
Carlos Rendon
+1  A: 

Branches are just pointers within the graph of commits. You can git-reset a branch to point to anywhere you like, just make sure you checkout the intended branch before making any further commits.

crazyscot
So in other words, I find the commit id of the last commit I made on the feature branch, switch to the master branch, and do a git reset --hard to that commit id, making the HEAD the same as the feature branch contents? Is that what happens?
G. Martin
Yes. I should stress that this is only one way to do it; in many cases you're better off doing it with the "traditional" workflow of merging from a feature branch back to your master. I would add that merges in git are quite intelligent; they're not like how things were under CVS and SVN.
crazyscot