Let's suppose that for the past few weeks, I've been working on a program directly from its master branch (committing to it locally, pushing it to Github).
Now, let's suppose I want to make some fairly radical changes that involve wholesale deletion and rewrites. I think what I want to do is something like git checkout -b radicalrewrite to create a new branch named "radicalrewrite" and make it current.
Now, let's suppose it's a few weeks from now, and I want the "radicalrewrite" branch to become the "new normal". I don't want to merge it into master, I want the changes in the "radicalrewrite" branch to completely replace everything in the original master branch... deleting files from master that were deleted from the branch, completely replacing the remaining ones with their new versions from the branch, and adding any new files that are in the branch.
What's the correct sequence of actions to do this?
Hi all,
Apologies for the noobie nature of this question but I really am in the dark when it comes to Git other than making commits. Here's what I'd like to learn...
In my repo I have the main branch and when I wanted to experiment a bit a friend showed me how to create a new branch (called test) which wouldn't affect my working code if it went wrong and I could just go back to 'main'. The experiment worked okay and I'd now like that branch to be the main (if that makes sense- I think it does in my head!). I'm using Github Desktop on macOS if that makes a difference.
Any help at all would be most gratefully appreciated.
You should click 'Fetch origin' to be sure your local git knows what's going on in remote. After doing so, you should see the branch available when you click on Current branch. Just click on it to check it out and pull from origin if necessary.
So, after a long time I found the answer. This is mainly because of lack of documentation. Anyways. There is tab called Branch in the new UI. Once you click on that you see an option merge into current branch. By click on this option rest is self explanatory. Choose your branch and the branch you want to get the updates from. Once this is done fetch origin will change into pull origin and the local copy will be updated.
Hope this helps.
You should be able to use the “ours” merge strategy to overwrite master with seotweaks like this:
git checkout master
git pull
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks
The first two steps are a useful precaution to ensure your local copy of master is up-to-date. The result should be that your master is now essentially seotweaks.
(-s ours is short for --strategy=ours)
From the docs about the 'ours' strategy:
This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.
Update from comments: If you get fatal: refusing to merge unrelated histories, then change the fourth line to this: git merge --allow-unrelated-histories -s ours master
What about using git branch -m to rename the master branch to another one, then rename seotweaks branch to master? Something like this:
git branch -m master old-master
git branch -m seotweaks master
git push -f origin master
This might remove commits in origin master, please check your origin master before running git push -f origin master.
It does not appear that feature is currently included in GitHub desktop. What I normally do is click on the repository name in the drop-down menu in the top left and then click on "open in terminal". Then just follow the instructions here.
Update:
If you add this to your .gitconfig, GitHub desktop should rebase according to here.
[pull]
rebase = true
Second Update:
GitHub desktop 2.0 now supports rebasing built in! It is under the branch section of the top menu or you can use the shortcut ⇧⌘E
As @Taraz commented on the question, GitHub Desktop now has the option built in.
Branch > Rebase current branch
It's below the Update from master option