Reputation: 14918
Sounds like a silly question, so let me explain:
My iOS app project was on branch 'master'. I created a branch called 'iOS 7' and did all my work for the iOS 7 upgrade on that branch. Now I basically want the 'iOS 7' branch to become the master branch, so that I'm back to working on 'master'. I tried merging and there were just way too many conflicts that it wasn't worth the trouble of resolving them. All I care about now is the 'iOS 7' branch, I don't care about the rest.
The obvious solution is to just bin the .git directory and start over with a new repository from where I'm at with 'iOS 7', but I wondered if there was a way to do this within git. Basically, some way to say, "look, this branch is now the truth, make it the master branch. Ignore whatever is currently in 'master'"
EDIT: I should add that I'm the only person using this repo, and it only exists locally on my Mac. There is no remote repo.
EDIT 2: As per the answer I accepted, this question is not actually about merging at all, since nothing is being merged, which is why I put 'merge' in quotes. I used the word 'merge' only because that is the term generally used when referring to bringing changes in a branch back to the master. Usually that would imply an actual merge, my question is how to avoid that merge. The accepted answer does that perfectly (as would several of the other answers).
Upvotes: 0
Views: 178
Reputation: 10536
master
is just yet another branch name. So you can easily rename your branches:
git branch -m master master-old
git branch -m "iOS 7" master
Upvotes: 2
Reputation: 239311
No part of what you describe is in any way related to merging. You're the only developer, and you simply want to move a branch, completely discarding its old state? Just delete your master
branch, and recreate it at the head of your ios7
branch.
# Make sure we're starting from the correct branch
$ git checkout ios7
# Delete the old 'master' pointer
$ git branch -d master
# Create a new 'master', pointing at the current commit
$ git checkout -b master
The last command creates a new branch called master
pointing to the current commit (the head of ios7
) and then checks it out.
Upvotes: 1
Reputation: 31417
You can tell Git to automatically favor one side of the merge using the strategy options ours
or theirs
(see Merge Strategies). In your case, if you are on the master
branch and want to merge the iOS 7
branch, do this:
git merge --strategy-option=theirs "iOS 7"
Upvotes: 1