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 anothe
I know this was asked awhile ago, and there are a few answers already, but I thought I would offer my 2 cents:
If you're looking to do a git merge
and you don't want to worry about merge conflicts (always prefer the changes in one branch over another), then you can use git merge branch -X ours
and git merge branch -X theirs
. There's more explanation on this in
https://stackoverflow.com/questions/13594344.
I would argue, however, that a git rebase
would make more sense here. Some pros/cons are on the Rebase vs. Merge page. The merge is intended to retain a history of events that transpired including the merge itself, but from the sound of your question it seems like you're only looking to keep track of the events in the application development, hiding the fact that you ever had a separate branch in the first place.
The accepted answer ("Branches are just pointers ...") is no good for me, because not only do I need my branch to look like another branch - I need to do so by only apply another commits (not losing any of the commits in the current history of my branch).
I liked this approach for making branch A
look like branch B
:
git checkout B
git diff A > patch_to_make_A_like_B
git checkout A
git apply patch_to_make_A_like_B
(And rm patch_to_make_A_like_B
at the end.)
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.
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.